dtu72460 2014-10-15 20:17
浏览 23

如何在PHP中请求用户ID或删除行

I need to delete a specific row in php.. so how could I get the ID or other way to delete a specific record

dbconnect.php just a simple database connection

<?php


    $con = mysqli_connect("localhost","root","","phpractice");

    if(mysqli_connect_errno()){
        echo "Database connection failed";
    }

?>

index.php the page where the user can see

<html>
<head>
<link rel="stylesheet" type="text/css" href="../styles/index.css">
</head>

<title>Home Page</title>

<?php include'../script/dbconnect.php';?>

<body>
<div id="container">

<div id="table">

<?php

 $result = mysqli_query($con,"SELECT * FROM users");


echo "<table border='1'>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Password</th>
<th colspan=2>Controls</th>
</tr>
";

 while($row = mysqli_fetch_array($result)){
    echo "<tr>";
    echo "<td>".$row['firstname']."</td>";
    echo "<td>".$row['lastname']."</td>";
    echo "<td>".$row['username']."</td>";
    echo "<td>".$row['password']."</td>";
    echo "<td>"."<a href='#'>EDIT</a>"."</td>";
    echo "<td><a href='../script/delete.php?id=".$row['user_id']."'>DELETE</a></td>";
    echo "</tr>";

 }

    echo "</table>";
?>
<a href="adduser.php" class="button">Add User</a>

</div><!--table-->
</div><!--container-->


</body>
</html>

delete.php the delete script

   <?php

include '../script/dbconnect.php';

$id = $_GET['user_id'];

$query = "DELETE FROM users WHERE user_id = $id";

mysqli_query($con, $query) or die (mysqli_error($con));

echo "DELETE USER SUCCESSFUL!";
echo "</br>";
echo "<a href='../main/index.php'>RETURN TO DISPLAY</a>";
?>

thanks in advance

  • 写回答

1条回答 默认 最新

  • duanna3634 2014-10-15 20:20
    关注

    in index.php use:

     echo "<td><a href='../script/delete.php?user_id=".$row['user_id']."'>DELETE</a></td>";
    

    then use $_GET['user_id']; in delete.php

    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数