Jump to content

delete only the entry with the specified id


Recommended Posts

I have  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'; 


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?


if(mysql_num_rows($emp_query) > 0){
	echo "<table border='1'>";
	echo "<th>Employee Id </th>";
	echo "<th>Employee Name </th>";
	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='400'>";
		echo $emp_name;
		$edit_path = 'edit_employee.php?id='.$emp_id;

		<INPUT TYPE="button" style="display:inline;" value="VIEW / EDIT" onClick="location.href='<?php echo $edit_path; ?>'"> 
		<form style='margin: 0; padding: 0; 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(isset($_POST['delbutton'])){
					$del_emp = mysql_query("DELETE from employee WHERE emp_id = '$emp_id'") or die(mysql_error());
		echo '</form>';

		echo "</td>";
		echo "</tr>";


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.