将下拉值添加到数据库?

时间:2017-11-15 05:35:33

标签: javascript php jquery mysql

在项目中工作,我有一个创建下拉菜单的按钮。菜单信息是从数据库生成的。当我尝试遍历所有内容以将选定的下拉值放入数据库时​​,什么也没发生。有什么想法吗?

PHP和HTML文件: 等到单击“完成”按钮,然后遍历数据库以创建我想要插入数据库的值的数组。

<!DOCTYPE HTML>
<?php 
include 'tools.php';
session_start(); 
require_once "sessionVerify.php";
?>

<script language="javascript">
i=1;
function addCourse(){
    var table=document.getElementById("courseList");
    var clnNode=document.getElementById("courserow").cloneNode(true);
    var clnNode2=document.getElementById("questionRow").cloneNode(true);
    var clnNode3=document.getElementById("ratingSelects").cloneNode(true);  
    table.insertBefore(clnNode,table.lastChild);
    table.insertBefore(clnNode2,table.lastChild);
    table.insertBefore(clnNode3,table.lastChild);
}
</script>
<!--
Editorial by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<?php
if( isset($_POST['finish'])){
    $i=0;
    $courseBuilder = queryDB("select * from Student;");
    $courseList = array();
    while($cb = $courseBuilder->fetch_assoc()){
        $courseList[$cb['FirstName']] = $cb['IUID'];
    }
    $arr = $_POST['enrolledCourses'];
    foreach($arr as $key){
        //queryDB("insert ignore into EnrollmentInput (SurveyID,CourseID,SemesterID) Values('".$_SESSION['curSurvey']."','".$courseList[$key]."','".$val."');");
        queryDB("insert ignore into Tesing (StudentNumber) Values('".$courseList[$key]."');");
    }
?>
<html>

    <head>
        <title>Mentor Rating of Student</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
        <!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
        <link rel="stylesheet" href="../assets/css/main.css" />
        <!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
        <!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
    </head>

    <body>

        <!-- Wrapper -->
        <div id="wrapper">

            <!-- Main -->
            <div id="main">
                <div class="inner">

                    <!-- Header -->
                    <header id="header">
                        <a href="" class="logo"><strong>Annual</strong> Self Study Form</a>
                    </header>

                    <!-- Content -->
                    <section>
                        <form action="MentorEvaluations.php" method="post">
                            <header class="main">
                                <h1>Mentor Evaluation</h1>
                            </header>

                            <h3>Mentor Name:</h3>
                            <?php printMentors();?>
                            <div class="table-wrapper" style="height:550px;border:1px solid #ccc;font:16px/26px Georgia, Garamond, Serif;overflow:auto;">
                                <table >
                                    <thead>
                                        <tr>
                                            <th></th>
                                            <!--<th>Semester</th>-->
                                        </tr>
                                    </thead>
                                    <tbody id="courseList">
                                            <?php printStartingRows();?>    
</tr>
                                            </tbody>
                                                                                    </table>
                                            </div>

                                                <button type="button" onclick="addCourse()">Add Another Student</button>
                                                <input name="finish" class="btn" type="submit" value="Finish Evaluation" />
                            </section>
                                </form>
                        </div>
                    </div>
                    <!-- Scripts -->
                    <script src="assets/js/jquery.min.js"></script>
                    <script src="assets/js/skel.min.js"></script>
                    <script src="assets/js/util.js"></script>
                    <!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
                    <script src="assets/js/main.js"></script>

                </body>

            </html>

用于打印表单的PHP函数:

function printStartingRows(){

    $result = queryDB("select * from EnrollmentInput where SurveyID=".$_SESSION['curSurvey'].";");
    $courseBuilder = queryDB("select IUID, FirstName from Student;");
    $courseList = array();
    while($cb = $courseBuilder->fetch_assoc()){
        $courseList[$cb['IUID']] = $cb['FirstName'];
    }

    while($row = $result->fetch_assoc()){
        print("<tr id='courserow'>");
        print("<td>");
        print("<h3>Student: </h3>");
        printCourseList($courseList[$row['CourseID']]);
        print("</td>");
        print("<td>");
        print("<h3>Student: </h3>");
    /*  printSemesterList($row['SemesterID']);
        print("</td>");
        print("</tr>");*/
        print("</tr>");

    }

    print("<tr id='courserow'>");

    print("<td>");
    print("<h3>Student: </h3>");
    printCourseList("");
        print("</td>");
    /*print("<td>");
    printSemesterList("");
    print("</td>");*/
    print("</tr>");

    print("<tr id='questionRow'>");
        print("<th>Motivation And General Attitude</th>");
    print("<th>Educational Initiative & Scholarship</th>");
    print("<th>Understanding of course material</th>");
    print("<th>Ability to apply course material</th>");
    print("<th>Oral English expression skills</th>");
    print("<th>Ability to analyze, integrate, and apply</th>");
    print("<th>Ethical standards & integrity</th>");
    print("<th>Respect for diversity</th>");
    print("</tr>");
    print("<tr id='ratingSelects'>");
    for ($xint=1; $xint<=8; $xint++){
    print('<td><select>     <option value="1">Poor</option>
        <option value="2">Less Than Acceptable</option>
        <option value="3">Satisfactory</option>
        <option value="4">Very Good</option>
    <option value="5">Excellent</option></select></td>');
    }
    print("</tr>");
    print("<br>");
}

最后,打印连接学生姓名的功能:

function printCourseList($s){//this is really print student

    $result = queryDB("SELECT concat (FirstName,' ', LastName) as StudentNames FROM `Student`");
    //$result = queryDB("SELECT *  FROM `Student`");
    // ^^ Unprofessional, fix later

    print('

        <input list="courses" name="enrolledCourses[]" value="'.$s.'">
        <datalist id="courses">');
    while($row = $result->fetch_assoc()){
        print('
            <option value="'.$row['StudentNames'].'"></option>
            ');
    }

    print('
        </datalist>
        ');
}

0 个答案:

没有答案