删除数据库后更新php

时间:2016-02-26 11:13:54

标签: php html mysql

这是user_list.php获取$ txt以查询“where like”的主页面。

<?php
      include_once('dbConfig.php');

    $result = mysqli_query($conn,"SELECT * FROM compid");
            <title>Computer Record</title>  
        </head>
        <body><thead>
                    <tr>
                                          <th id='time'> </th>
                                            <th>Computer ID</th>
                                            <th id='time'>ComputerName</th>
                                            <th id='title'>Status</th>
                                            <th id='cost'>IP</th>
                                            <th id='size'>OS</th>
                                            <th id='author'>RAM</th>
                                                  <th id='author'>CPU</th>
                                                        <th id='author'>Machine Model</th>
                                                              <th id='author'>Serial Number</th>
                                                                    <th id='author' >Remarks</th>
                                                                          <th id='author'>Application</th>
                                                                          <th id='author'>User</th>
    <th id='author'>Delete</th>
    <th id='author'>Edit</th>
                    </tr></thead>
                    ";
                                    while($row = mysqli_fetch_array($result))
      {
                    echo"<tbody>";

          echo "<td><input type='checkbox' name='Days[]' value=". $row['cid'] ."> </td>";               
      echo "<td>" . $row['cid'] . "</td>";
      echo "<td>" . $row['cname'] . "</td>";
      echo "<td>" . $row['stat'] . "</td>";
      echo "<td>" . $row['ip'] . "</td>";
        echo "<td>" . $row['os'] . "</td>";
      echo "<td>" . $row['ram'] . "</td>";
      echo "<td>" . $row['cpu'] . "</td>";
      echo "<td>" . $row['mmodel'] . "</td>";
      echo "<td>" . $row['snumber'] . "</td>";
      echo "  <td>" . $row['remarks'] . "</td>";
      echo "<td ><a href='App_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/view.png' style='border-style: none'></a></td>";
          echo "<td><a href='User_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/user_group.png' style='border-style: none'></a></td>";
      echo "<td><a href='del_Main.php?ID=" . $row['ID'] . "' onclick='return checkDelete()'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/erase.png' style='border-style: none'></a></td>"; 
       echo "<td><a href='Edit_Main.php?ID=" . $row['ID'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/edit.png' style='border-style: none'></a></td>";               
                                    }
    echo "</table>";?>
?>

这是User_List.php

   if(isset($_GET['cname'])) {
$txt= $_GET['cname'];
$result = mysqli_query($con,"SELECT * FROM user Where cname like '$txt'");
 echo"<body bgcolor='#696969'>
          <input type='submit' value='Export'  method='post'>
         </head>";
echo "<table border='1'>
<tr>

<th>Users</th>
<th> </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
    $one = $row['cname']; 
echo "<tr>";

echo "<td>" . $row['user'] . "</td>";
   echo "<td><a href='User_List.php?ID=" . $row['ID'] . "' onclick='return checkDelete()'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/erase.png' style='border-style: none'></a></td>";  echo "</tr>";


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

这是我在表格中的删除按钮如何更新页面这是delete.php:

if(isset($_GET['ID'])) {

$result = mysqli_query($conn,"DELETE FROM `SGSCOMP`.`user` WHERE `user`.`ID` = ".$_GET["ID"]);
}

如何返回用户列表

2 个答案:

答案 0 :(得分:0)

要返回User_List.php,您只需使用header()即可。这将在运行mysqli_query后重定向用户。

您应该使用mysqli_affected_rows()检查是否已成功删除该行。这将返回受影响的行数,即如果删除了1行,则返回1。

if(isset($_GET['ID'])) {

    $result = mysqli_query($conn,"DELETE FROM `SGSCOMP`.`user` WHERE `user`.`ID` = ".$_GET["ID"]);

    if (mysqli_affected_rows($conn) > 0) {
        header("Location:User_List.php");
        exit;
    } else { 
        // row was not deleted successfully
    }

}

有关http://www.w3schools.com/php/func_http_header.aspheader()的更多信息。

  

对于User_Main.php,它应该是:

您无法将<?php标记放在<?php标记内。

<?php
  include_once('dbConfig.php');

$result = mysqli_query($conn,"SELECT * FROM compid");

?>

        <title>Computer Record</title>  
    </head>
    <body><thead>
                <tr>
                                      <th id='time'> </th>
                                        <th>Computer ID</th>
                                        <th id='time'>ComputerName</th>
                                        <th id='title'>Status</th>
                                        <th id='cost'>IP</th>
                                        <th id='size'>OS</th>
                                        <th id='author'>RAM</th>
                                              <th id='author'>CPU</th>
                                                    <th id='author'>Machine Model</th>
                                                          <th id='author'>Serial Number</th>
                                                                <th id='author' >Remarks</th>
                                                                      <th id='author'>Application</th>
                                                                      <th id='author'>User</th>
<th id='author'>Delete</th>
<th id='author'>Edit</th>
                </tr></thead>
<?php
                                while($row = mysqli_fetch_array($result))
  {
                echo"<tbody>";

      echo "<td><input type='checkbox' name='Days[]' value=". $row['cid'] ."> </td>";               
  echo "<td>" . $row['cid'] . "</td>";
  echo "<td>" . $row['cname'] . "</td>";
  echo "<td>" . $row['stat'] . "</td>";
  echo "<td>" . $row['ip'] . "</td>";
    echo "<td>" . $row['os'] . "</td>";
  echo "<td>" . $row['ram'] . "</td>";
  echo "<td>" . $row['cpu'] . "</td>";
  echo "<td>" . $row['mmodel'] . "</td>";
  echo "<td>" . $row['snumber'] . "</td>";
  echo "  <td>" . $row['remarks'] . "</td>";
  echo "<td ><a href='App_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/view.png' style='border-style: none'></a></td>";
      echo "<td><a href='User_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/user_group.png' style='border-style: none'></a></td>";
  echo "<td><a href='del_Main.php?ID=" . $row['ID'] . "' onclick='return checkDelete()'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/erase.png' style='border-style: none'></a></td>"; 
   echo "<td><a href='Edit_Main.php?ID=" . $row['ID'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/edit.png' style='border-style: none'></a></td>";               
                                }
echo "</table>";
?>
  

User_List.php

你没有用另一个大括号关闭if(isset($_GET['cname'])) {

  

对于delete.php,它应该是:

没有必要将字符串连接起来,因为它是还原剂。

if(isset($_GET['ID'])) {

   $result = mysqli_query($conn, "DELETE FROM `SGSCOMPuser` WHERE `userID` = '$_GET["ID"]');
}

答案 1 :(得分:0)

您可以在delete.php的更新查询后直接进行header重定向。

header("location:User_List.php")

这会将用户重定向回User_List.php

  

header()用于发送原始HTTP标头。有关HTTP标头的详细信息,请参阅»HTTP / 1.1规范。

相关问题