需要有关在一个查询中存储不同行的帮助

时间:2016-11-07 02:52:36

标签: php html sql

大家好我需要一些帮助:/我的代码有问题。

每当我尝试提交显示的数据时,只有1行存储在数据库中。有没有办法将我的所有数据存储在1个查询中?

这是我的代码:

<?php

    if (isset($_POST['search'])){

        $dbHost="localhost";
        $dbUser="root";
        $dbPass="";
        $dbName="enrollmentsystem";
        $con = mysqli_connect($dbHost,$dbUser,$dbPass);

        $saccount = $_POST['saccount'];

        mysqli_select_db($con,$dbName);

        $sql = "SELECT * FROM studentaccount WHERE student_number='$saccount'";
        $data = mysqli_query($con,$sql);

        $row = mysqli_fetch_array($data);
        $fsection = $row['section'];

        $sqlano = "SELECT * FROM class WHERE section='$fsection'";
        $dataano = mysqli_query($con,$sqlano);


        while ($scheduledata = mysqli_fetch_array($dataano))
                {   

                    echo "<form action='enroll.php method='POST'><tr>
                    <td><input type='text' name='tnumber' value='{$scheduledata['teacher_number']}'/></td>
                    <td><input type='text' name='cnumber' value='{$scheduledata['class_number']}'/></td>
                    <td><input type='text' name='scode' value='{$scheduledata['subject_code']}'/></td>
                    <td><input type='text' name='section' value='{$scheduledata['section']}'/></td>
                    <td><input type='text' name='room' value='{$scheduledata['room']}'/></td>
                    <td><input type='text' name='days' value='{$scheduledata['days']}'/></td>
                    <td><input type='text' name='start' value='{$scheduledata['start_at']}'/></td>
                    <td><input type='text' name='ends' value='{$scheduledata['ends_at']}'/></td>
                    </tr> </form>";

                }
    }

?>
</table>

<input type="submit" name="enroll" value="Enroll">

<?php

    if (isset($_POST['enroll']))
        {
            $dbHost="localhost";
            $dbUser="root";
            $dbPass="";
            $dbName="enrollmentsystem";
            $con = mysqli_connect($dbHost,$dbUser,$dbPass);

                // if (!$con)
                // {
                //  die("Connection Error" . mysql_error());
                // }

                // echo "Connected Succesfully!";

            mysqli_select_db($con,$dbName);

            $insertQuery = "INSERT INTO grades (class_number,student_number,subject_code,section,teacher_number)

             VALUES('$_POST[cnumber]','$_POST[saccount]','$_POST[scode]','$_POST[section]','$_POST[tnumber]')";

            mysqli_query($con,$insertQuery);

        }
?>

0 个答案:

没有答案