I am doing a website with login system were each user can insert and view his logs.
Now I am trying to make a delete button that when clicked an entire row from a table is deleted.
It is working fine because when I click the "DELETE BUTTON" and check the rows from thee phpmyadmin shell the row is no longer there.
The problem is that on the first click the row is still visible in the webpage and only when I click the button again it disappears!
Here is my code: -
<?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']."' ");
}
?>