2013-06-01 43 views
-1

我有从数据库中删除数据的问题,我做了一个表,它将显示注册用户的名称和密码。并在他们旁边有一个删除链接。 当我按下删除链接,它给了我一个错误。从数据库中删除数据在php中

这里是viewTheUsers.php页

<html> 
<head> 
<title>the users</title> 
</head> 
<body> 
<table width ="650" align ="center" border ="2" >  
<tr> 
<th width="60">User No </th>  
<th>User Name </th> 
<th>User Password </th> 
<th>Delete User </th> 
</tr>  
<?php 
mysql_connect("hostName","userName","password"); 
mysql_select_db("db_name"); 
$Thequery = "SELECT * FROM table_name"; 
$run = mysql_query($Thequery); 
while($row = mysql_fetch_array($run)){ 
$The_id = $row[0];  
$The_name = $row[1]; 
$The_pass = $row[2]; 
?> 
<tr> 
<td><?php echo $The_id; ?></td>  
<td><?php echo $The_name; ?></td> 
<td><?php echo $The_pass; ?></td> 
<td><a href="delete.php?deleting=<?php echo $The_id; ?>">Delete</a></td> 
</tr> 
<?php }?> 
</table> 
</body> 
</html> 

这里是delete.php页:

<?php 
mysql_connect("hostName","userName","password"); 
mysql_select_db("db_name"); 
$deleting_id = $_GET['deleting']; 
$Thequery = "delete from users where id = '$deleting_id' "; 
if (mysql_query($Thequery)){ 
echo "<script>window.open('viewTheUsers.php?deleted = user has been deleted!!!','_self')</script>";  
} 
?> 

的massege错误说:

公告:未定义索引:在C:\ wamp \ www \ delete中删除.php on line 6

+0

你知道mysql。*函数被折旧吗? – imulsion

+1

delete.php的第6行是什么? – Barmar

+3

这个错误表明你有'$ _GET ['del']'在你的脚本代替'$ _GET ['删除']'检查输入错误 – Barmar

回答

1

请注意,此代码存在许多问题。其中之一是注入问题,你只需将get变量中的所有内容直接放入数据库查询中即可。此外,该window.open调用打开一个无效的网址(我想它可能会工作,但你应该做的空间等网址编码)。要挑剔,你的变量命名实际上是非标准的(第一个字母大部分是小写,为什么要在每个地方加上'''',但这不是真正的biggy)。

最后,检查第6行。错误的意思是“你正试图访问一个数组中的值,但你正在使用的索引('del')根本不存在。 $_GET['del']并且它没有设置

+0

我很抱歉,我得到的消息错误是:注意:未定义的索引:在第6行删除C:\ wamp \ www \ delet.php所以它删除而不是删除 – user2442835

+2

请考虑剪切/粘贴,这个通知也有一个错字。虽然这一点是相同的:'$ _GET ['deleted'];'不存在。 'var_dump'你的数组,检查你的url,并且修正你的delete ID是空的事实。可能是某处的错字。现在开始调试,您知道通知的原因。 – Nanne