gpt4 book ai didi

php - 我的删除程序在 php 中不起作用

转载 作者:行者123 更新时间:2023-11-29 23:16:17 25 4
gpt4 key购买 nike

我的删除程序在 php 中不起作用。

下面的代码显示了信息,但是删除代码不起作用,我哪里出错了?

连接已建立,但删除代码不起作用,为什么?

connection.php

<?php

// Database Connection
$con = mysql_connect("localhost","sathishcst","geni7joy");
mysql_select_db("practice",$con);
?>

显示.php

<?php
require_once 'connection.php';
$query = "select * from pays";
$data = mysql_query($query);
?>
<html>

<body>
<table border=”1″ cellpadding=”5″>
<tr>
<th>Id</th> <th>NewsList</th> <th>Anchor link</th> <th colspan=”2″>Action</th>
</tr>
<?php while($rec = mysql_fetch_array($data)) { ?>
<tr>
<td> <?php echo $rec['id']; ?> </td>
<td> <?php echo $rec['name']; ?> </td>
<td> <?php echo $rec['email']; ?> </td>
<td> <a href=”edit.php?id=<?php echo $rec['id']; ?>”>edit</a> </td>
<td> <a onClick="return confirm('Sure to delete!')" href="delete.php?id=<?php echo $rec['id']; ?>">delete</a> </td>
</tr>
<?php } ?>
</table>
</body>
</html>

删除.php

<?php
require_once “connect.php”;
$msg = “”;
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : “0″;
$query = “delete from tbemp where id=”.$id;
if(mysql_query($query)) {
header(“location:display.php”);
} else {
echo “unable to delete!”;
}
?>

最佳答案

您在 delete.php 文件中犯了错误。在where子句之后,您需要使用$_REQUEST['id']而不是$id

试试这个代码:

<?php
require_once "connect.php";
$msg = "";
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : "0";
$query = "delete from tbemp where id=".$_REQUEST['id'];
if(mysql_query($query)) {
header("location:display.php");
} else {
echo "unable to delete!";
}
?>

关于php - 我的删除程序在 php 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27772727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com