如何在PHP中请求用户ID或删除行
我需要删除php中的特定行。。那么,我如何获得ID或以其他方式删除特定记录呢 php只是一个简单的数据库连接如何在PHP中请求用户ID或删除行,php,mysql,Php,Mysql,我需要删除php中的特定行。。那么,我如何获得ID或以其他方式删除特定记录呢 php只是一个简单的数据库连接 <?php $con = mysqli_connect("localhost","root","","phpractice"); if(mysqli_connect_errno()){ echo "Database connection failed"; } ?> index.php用户可以看到的页面 <html&g
<?php
$con = mysqli_connect("localhost","root","","phpractice");
if(mysqli_connect_errno()){
echo "Database connection failed";
}
?>
index.php用户可以看到的页面
<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删除脚本
<?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>";
?>
提前感谢在index.php中使用:
echo "<td><a href='../script/delete.php?user_id=".$row['user_id']."'>DELETE</a></td>";
echo”“;
然后使用
$\u GET['user\u id']
在delete.php中我认为您的答案很酷,但我得到了一些错误。。你能检查一下我上面更新的脚本吗?看看delete.php。。注意:未定义的索引:C:\xampp\htdocs\practicephp\script\delete.php中的user\u id在第5行url应该有user\u id
而不是id
,或者更改$\u GET
什么。。。没有绿色的ticky?delete.php?id
应该是delete.php?user\u id
,因为您使用的是$\u GET['user\u id']
@Dagon啊,想想看,晚餐铃刚刚响了。