**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答案。
这个问题是由一个打字错误或一个无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
13个小时前关门了。
Improve this question
我想更新和删除也我的数据使用php和我想显示在当前表我的数据我更新.但我不知道为什么我的代码不工作,我尝试了这么多的代码来测试,但它不工作.这里我的代码在update edit.php
<?php
include 'conn.php';
$id = '';
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$view = "SELECT * FROM user_2";
$result = $db->query($view);
$row = $result->fetch_assoc();
if (isset($_POST['update'])) {
$id = '';
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$fn = $_POST['fname'];
$ln = $_POST['lname'];
$insert = "UPDATE user_2 SET firstname = '$fn', lastname = '$ln' WHERE 'id' = '$id' ";
if ($db->query($insert) == TRUE) {
echo '<script>alert("Updated Succesfully")</script>';
header("refresh:1; url=index.php");
} else {
echo "Update unsuccessfully";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="edit.php" method="post">
<table align="center">
<tr>
<td>
First Name: <input type="text" name="fname" value="<?php echo $row['firstname']; ?>" placeholder="First Name">
</td>
</tr>
<tr>
<td>
Last Name: <input type="text" name="lname" value="<?php echo $row['lastname']; ?>" placeholder="Last Name">
</td>
</tr>
<tr>
<td>
<input type="submit" name="update" value="UPDATE">
</td>
</tr>
</table>
</form>
</body>
</html>
我想删除我的数据使用php,但它不工作也.这里是我的代码在delete delete.php
<?php
include 'conn.php';
$id = '';
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$sql = "DELETE FROM user_2 WHERE md5(id) = '$id' ";
if ($db->query($sql) == true) {
echo "Succesfully deleted";
} else {
echo "deleted unsuccessfully";
}
?>
我想显示我的数据我更新了我的表,但如果我更新了它,它不工作的当前数据将显示.不是更新的数据.
<table align="center" border="5" cellspacing="0" width="500">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php
$sql = "SELECT * FROM user_2";
$result = $db->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_array()) {
?>
<tr class="tdt">
<td align="center"> <?php echo $row['firstname']; ?></td>
<td align="center"> <?php echo $row['lastname']; ?></td>
<td align="center"><a href="edit.php ? id = <?php echo md5($row['id']); ?> "> Edit </a> </td>
<td align="center"> <a href="delete.php?id = <?php echo md5($row['id']); ?>"> Delete </a></td>
</tr>
<?php
}
} else {
echo "<center><p>No records</p></center>";
}
?>
</table>
1条答案
按热度按时间krugob8w1#
在您的更新代码中,您说
where 'id' = '$id'
,它应该是where id = '$id'
(id不应该用引号括起来),在删除代码中,为什么要对id进行哈希处理?比较失败,因此只需将其重构为
DELETE FROM user_2 WHERE id = '$id'
。在html代码中,请传递正确的id:您的代码:
<a href="edit.php ? id = <?php echo md5($row['id']);
更改为类似以下内容:
<a href="edit.php ? id = <?php echo base64_encode($row['id']);
然后在edit.php中访问它,如下所示:
$id = base64_decode($_GET['id])
您的代码:
<a href="delete.php?id = <?php echo md5($row['id']); ?>"
更改为:
<a href="delete.php?id = <?php echo base64_encode($row['id']); ?>"
然后在delete.php中访问它,如下所示:
$id = base64_decode($_GET['id])