php mysql更新和删除不会对home.php生效

时间:2015-12-15 12:36:56

标签: php mysql

我如何使$ UpdateQuery和$ DeleteQuery函数工作我已经输入这些代码才能运行但home.php文件中没有进行任何更改?

这些是update.php中的代码: [this is my database used named ruiz with the table 'registry']

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

$UpdateQuery = "UPDATE registry SET db_id = '$_POST[db_id]', db_name = '$_POST[db_name]', db_age = '$_POST[db_age]', db_gender = '$_POST[db_gender]', db_birthdate = '$_POST[db_birthdate]', db_phone = '$_POST[db_phone]', db_address = '$_POST[db_address]' 
                WHERE db_id = '$_POST[hidden]'";
                mysqli_query(UpdateQuery);

        //redirect to home.php
        header('Location: home.php');

            }

            $query= mysqli_query( $DB,"SELECT * FROM registry" );

        echo"<h2><center>Employee Masterlist</center></h2>";
        echo "<table class = \"form\" border = \"1\" cellspacing = \"3\">";
        echo "<tr>";
        echo "<th>Employee ID</th>";
        echo "<th>Name</th>";
        echo "<th>Age</th>";
        echo "<th>Gender</th>";
        echo "<th>Birthdate </th>";
        echo "<th>Phone No. </th>";
        echo "<th>Address </th>";
        echo "</tr>";


            if(mysqli_num_rows($query) > 0){
            while($row = mysqli_fetch_assoc( $query))
            {
                    echo "<form action=update.php method=post>";
                    echo "<tr>";
                    echo "<td>" . "<input id=input-up type=text name=db_id 
                    value=" . $row['db_id'] . "> </td>";
                    echo "<td>" . "<input id=input-up type=text name=db_name 
                    value=" . $row['db_name'] . "> </td>";
                    echo "<td>" . "<input id=input-up type=text name=db_age 
                    value=" . $row['db_age'] . "> </td>";
                    echo "<td>" . "<input id=input-up type=text 
                    name=db_gender value=" . $row['db_gender']. "> </td>";
                    echo "<td>" . "<input id=input-up type=text 
                    name=db_birthdate value=" . $row['db_birthdate'] . ">   
                        </td>";
                    echo "<td>" . "<input id=input-up type=text 
                    name=db_phone value=" . $row['db_phone'] . "> </td>";
                    echo "<td>" . "<input id=input-up type=text 
                    name=db_address value=" . $row['db_address'] . ">
                    </td>";
                    echo "<input type=hidden name=hidden value=" . 
                    $row['db_id'] . "> </td>";
                    echo "<td>" . "<input class=send_btn type=submit 
                    name=update value=Update". "> </td>"; 
                    echo "</tr>";
                    echo "</form>";

            }
            }
            echo"</table>";
                ?>  
                    </div>
                    </body>
                    </html>

这些是delete.php中与前一个数据库相同的代码,带有表'registry'的ruiz

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

$DeleteQuery = "DELETE FROM registry WHERE db_id = '$_POST[hidden]'";
mysqli_query($DeleteQuery);

//redirect to home.php
header('Location: home.php');

            }       

            $query= mysqli_query( $DB,"SELECT * FROM registry" );


        echo"<h2><center>Employee Masterlist</center></h2>
        <table class = \"form\" border = \"1\" cellspacing = \"3\">
        <tr>
        <th>Employee ID</th>
        <th>Name</th>
        <th>Age</th>
        <th>Gender</th>
        <th>Birthdate </th>
        <th>Phone No. </th>
        <th>Address </th>
        </tr>";


            if(mysqli_num_rows($query) > 0){
            while($row = mysqli_fetch_assoc( $query))
            {
                    echo "<form action=delete.php method=post>";
                    echo "<tr>";
                    echo "<tr>";
                    echo "<td>".$row['db_id']."</td>";
                    echo "<td>".$row['db_name']."</td>";
                    echo "<td>".$row['db_age']."</td>";
                    echo "<td>".$row['db_gender']."</td>";
                    echo "<td>".$row['db_birthdate']."</td>";
                    echo "<td>".$row['db_phone']."</td>";
                    echo "<td>".$row['db_address']."</td>";
                    echo "<input type=hidden name=hidden value=" . $row['db_id'] . "> </td>";
                    echo "<td>" . "<input class=send_btn type=submit name=delete value=Delete". "> </td>";
                    echo "</tr>";
                    echo "</form>";

            }
                }
            echo"</table>";
?>  

1 个答案:

答案 0 :(得分:0)

$delete_id = $_GET['del'];

$query = "delete from users where id='$delete_id'";

if(mysql_query($query)){
echo
"<script>
window.open('home.php')
</script>";
}

尝试这样做并回复我,如果它有效或你有任何问题