I have am writing a code where I can edit or delete certain details from the database.
Right now, if the user clicks on the edit button it takes him edit page where he can edit the details.
But, I am not able to Incorporate a Delete button such that, when the user clicks on a delete button,
it should ask for a confirmation box. If the user clicks YES, then do the following:
DELETE from emp WHERE emp_id='$emp_id';
Here is my code so far
while($get_emp = mysql_fetch_assoc($emp_query)){
$emp_id = $get_emp['emp_id'];
$emp_name = $get_emp['first_name']." ".$get_emp['last_name'];
echo "<tr>";
echo "<td width='100'>";
echo $emp_id;
echo "</td>";
echo "<td width='300'>";
echo $emp_name;
$edit_path = 'edit_employee.php?id='.$emp_id;
?>
<INPUT TYPE="button" value="EDIT" onClick="location.href='<?php echo $edit_path; ?>'">
<?
echo "</td>";
echo "</tr>";
}
ok so i tried the following code and it works…but after it deletes the row, it doesnt seem to refresh the page. I mean the entry is still visible in the page. I need to refresh the page to clear it out..
<form style='margin: 0; padding: 0;' style='display:inline;' method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onSubmit="return confirm('Are you sure this is correct?');">
<input style='display:inline;' name="delbutton" type="submit" value="DELETE">
<?php if(!empty($_POST['delbutton'])){
$del_emp = mysql_query("DELETE from employee WHERE emp_id = '$emp_id'") or die(mysql_error());
header('Location:page.php');
}
echo '</form>';
ok as per kevin’s suggestion I added the header part.
I have one more issue to deal with.. When there are multiple entries and I click on delete it deletes everything from the database. How can I make it to delete only the entry that is besides the delete button?
you could do something like …