我正在做一个带有登录系统的网站,每个用户都可以插入和查看他的日志。
现在我正在尝试制作一个删除按钮,当单击表格中的整行时,该按钮将被删除。
它工作正常,因为当我单击“删除按钮”并检查 phpmyadmin shell 中的行时,该行不再存在。
问题是,在第一次单击时,该行在网页中仍然可见,只有当我再次单击该按钮时,它才会消失!
这是我的代码: -
<?php
$entries = mysql_query("SELECT `id`,`date`, `location`, `description` FROM `logs` WHERE `username` = '$current_user'");
if(mysql_num_rows($entries)==0){
echo 'No entries, yet.';}
else{
while($entries_row = mysql_fetch_assoc($entries)){
echo "
<hr>
<form action='' method='post'>
<input type='hidden' name='id' value='".$entries_row['id']."'>
<table align='center' border='1' width='80%' cellpadding='5'>
<tr>
<td width='20%'><strong>Date:</strong></td>
<td>" . $entries_row['date'] . "</td>
</tr>
<tr>
<td width='20%'><strong>Location:</strong></td>
<td>" . $entries_row['location'] . "</td>
</tr>
<tr>
<td width='20%'><strong>Description:</strong></td>
<td>" . $entries_row['description'] . "</td>
</tr>
<tr>
<td colspan='2' align='right'><input type='submit' name='delete' value='Delete Entry'></td>
</tr>
</table>
</form>
";
}
}
}else{
echo 'Could not connect at this time.';
}
if(isset($_POST['delete']))
{
mysql_query("DELETE FROM `logs` WHERE `id` = '".$_POST['id']."' ");
}
?>