management.php是一个通过表格获取php信息的代码。 而managementdel.php是del信息的代码。 我使用mysql_fetch_array来显示所有数据,并且每个信息旁边都有一个要删除的herf 回显数据库中的数据。
当我del时,里面没有错误。但数据库信息没有删除。
management.php
$con1 = mysql_connect("127.0.0.1","root","password");
mysql_select_db("babytradeapps");
$sql1 = "Select LoginID , Password , Permission
from loginacc where Permission = 2 ";
$results = mysql_query($sql1,$con1);
echo "<tr><th>會員帳號</th></tr>";
echo "<table border=5 cellpadding=10>";
echo "<tr><th></th><th>帳號</th><th>密碼</th><th>權限</th><th></th><th></th></tr>";
while($row = mysql_fetch_array($results)) {
echo "<tr><td>
<a href='searchtable.php?lid=$row[0]'>get information</a></td><td>$row[0]</td><td><input type=text id='row1' name='row1' value='$row[1]' /></td>
<td>$row[2]</td><td>
<a href='searchtable.php?lid=$row[0]'>Change</a></td><td>
<a href='managementdel.php?lid=$row[0]'>Delete</a></td></tr>";
}
echo "</table>";
managementdel.php
<?php
$ac = $_GET['rowname'];
$con = mysql_connect("127.0.0.1","root","password");
mysql_select_db("babytradeapps");
$sql = "delete from loginacc where LoginID = '$ac'";
if(mysql_query($sql))
{
echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';
}
else
{
echo 'fail!';
echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';
}
echo mysql_error()
?>
答案 0 :(得分:1)
您的脚本存在很多错误,我不会解决所有问题。我要做的就是回答你问的问题:&#34;为什么它不会从数据库中删除。&#34;
你的剧本有什么问题:
mysql_*
库(参见下面的注释)meta refresh
重定向而不是header('Location: link');
$_GET['lid']
。如上所述,您正试图获取:
$_GET['rowname']
当你发送lid
- &gt; managementdel.php?lid=$row[0]
。您必须将其更改为:
$ac = $_GET['lid'];
由于库已折旧,请远离mysql_*
函数。
使用以下任一两个代替:
如果您不打算这样做,请至少尝试并清理您的用户输入以防止SQL注入。
使用intval()
和mysql_real_escape_string()
等功能会对您有所帮助,但不会像PDO / mysqli那样全面。
答案 1 :(得分:0)
在managementdel.php文件中而不是
$ac = $_GET['rowname'];
应该有
$ac = $_GET['lid'];
答案 2 :(得分:0)
尝试
<强> management.php 强>
<?php
$con1 = mysql_connect("127.0.0.1","root","password");
mysql_select_db("babytradeapps");
$sql1 = "Select LoginID , Password , Permission
from loginacc where Permission = 2 ";
$results = mysql_query($sql1,$con1);
echo "<tr><th>會員帳號</th></tr>";
echo "<table border=5 cellpadding=10>";
echo "<tr><th></th><th>帳號</th><th>密碼</th><th>權限</th><th></th><th></th></tr>";
while($row = mysql_fetch_array($results)) {
echo "<tr><td>
<a href='searchtable.php?lid= " . $row[0] . "'>get information</a></td><td>" . $row[0] . "</td><td><input type=text id='row1' name='row1' value='" . $row[1] . "' /></td>
<td>" . $row[2] . "</td><td>
<a href='searchtable.php?lid=" . $row[0] . "'>Change</a></td><td>
<a href='managementdel.php?lid=" . $row[0] . "'>Delete</a></td></tr>";
}
echo "</table>";
?>
<强> managementdel.php 强>
<?php
$ac = $_GET['lid'];
$con = mysql_connect("127.0.0.1","root","password");
mysql_select_db("babytradeapps");
$sql = "delete from loginacc where LoginID = '$ac'";
if(mysql_query($sql))
{
echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';
}
else
{
echo 'fail!';
echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';
}
echo mysql_error()
?>