【发布时间】:2016-02-22 19:26:55
【问题描述】:
当我单击 drop 时,我遇到了功能无法正常工作的问题,所以这里有什么问题 我只需要在单击 drop 时删除记录,所以请提供任何帮助 函数 drop 中的查询是否正确?
<?php
$sql="SELECT * FROM administrators";
$record=mysql_query($sql);
function drop($id,$email){
$q="DELETE FROM administrators WHERE id='$id' AND email='$email'";
mysql_query($q);
}
?>
<title>Admins Table</title>
<style>
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
#creating {
font:bold;
font-size:1.6em;
}
</style>
<a href='cadmin.php' id='creating'>Create New Admin</a><br/><br/>
<table width="920" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php
while($row=mysql_fetch_assoc($record)){
echo'<tr>';
echo'<td>'.$row['id'].'</td>';
echo'<td>'.$row['first_name'].'</td>';
echo'<td>'.$row['last_name'].'</td>';
echo'<td>'.$row['phone'].'</td>';
echo'<td>'.$row['gender'].'</td>';
echo'<td>'.$row['email'].'</td>';
echo'<td>'.$row['address'].'</td>';
echo'<td>'."<a href='' onclick=''>Edit</a>".'</td>';
echo'<td>'."<a href='' onclick='".drop($row['id'],$row['email'])."'> Drop</a>".'</td>';
echo'</tr>';
}
?>
</table>
//code here
【问题讨论】:
-
我推荐使用mysqli
-
我推荐使用 PDO ;)
-
糟糕的 HTML 和 PHP 代码。发现很多错误。您不能只通过
onclick调用 PHP 函数。请了解服务器端脚本和客户端脚本的区别。 -
@joee 见this tutorial