数据未正确保存

时间:2017-04-01 12:49:33

标签: php html

所以这是我的代码的一部分。我的问题是保存按钮,它不能正确保存我的数据。无论我在下拉列表中做出什么选择,它都会插入固定数据。这段代码有什么问题吗?谢谢。

<div class="container">
        <div class ="wrapper">
            <h1>Registration</h1>
        </div>
        <div class="data">
            <form action="index.php" method="POST">
            <h3> Select the relative fields</h3>
            <select name="programme" >
                <option selected disabled>Programmes</option>

                <?php
                    $query = "SELECT * FROM programmes_list";
                    $result =  mysqli_query($link, $query);
                    while($rows1 = mysqli_fetch_assoc($result)){
                    $programmeID = $rows1['programme_no'];
                    $rowsData1 = $rows1['programme_name'];
                    ?>
                        <option value ="<?php echo $programmeID; ?>"><?php echo $rowsData1; ?></option>

                    <?php   
                    }
                ?>
            </select>
            <select name="intake" >
                <option selected disabled>Intake</option>
                <?php
                    $query2 = "SELECT * FROM intakes";
                    $result2 =  mysqli_query($link, $query2);
                    while($rows2 = mysqli_fetch_assoc($result2)){
                    $intakeID = $rows2['intake_no'];
                    $rowsData2 = $rows2['intake_list'];
                    ?>
                        <option value ="<?php echo $intakeID; ?>"><?php echo $rowsData2; ?></option>

                    <?php   
                    }
                ?>
            </select>
            <input type="submit" name="submit" class="submit" />
            <table border="1" class="table">
                <tr>
                    <th>Subject Codes</th>
                    <th>Subject Name</th>
                </tr>

                <?php
                if(isset($_POST['submit'])){

                    $programmeName =$_POST['programme'];
                    $intakeName =$_POST['intake'];

                    $query3 = "SELECT subject_list.subject_code, subject_list.subjects
                            FROM subject_list
                            WHERE subject_list.programme_id= '$programmeName'
                            AND subject_list.intake_id= '$intakeName'";
                    $result3 =  mysqli_query($link, $query3);
                    while($rows3 = mysqli_fetch_assoc($result3)){
                    $subjectCode = $rows3['subject_code'];
                    $subjectName = $rows3['subjects'];
                    ?>
                    <tr>
                         <td><?php echo $subjectCode; ?></td>
                         <td><?php echo $subjectName; ?></td>
                    </tr>
                    <?php   
                    }
                    }


                ?>

            </table>
            <br>
            <h4>Please enter your desired subjects with the respective subject codes.</h4>
            <h4>(Enter comma-> ',' for multiple selections)</h4>
            <input type="text" name="subjects_selected" value="">
            <input type="submit" name="enter" class="enter" />
            <?php
            if(isset($_POST['enter'])){ // Fetching variables of the form which travels in URL
                $subjectSelected = $_POST['subjects_selected'];

                if($subjectSelected !=''){
                //Insert Query of SQL
                $query4 = mysqli_query($link, "insert into registered(programme_registered, intake_registered, subjects_registered) values ( '$rowsData1', '$rowsData2', '$subjectSelected')");
                echo "<br/><br/><span>You ave registered your subjects!!</span>";
                }
            }
            ?>
            </form>
        </div>
    </div>

0 个答案:

没有答案