The function of delete record is working, but you need to double click the Delete Button to successfuly delete the record...can anyone help me pls

<?php
$con = mysql_connect("localhost","root","");
$sql = mysql_select_db("luweegee",$con);
$sel = mysql_query("SELECT * FROM resume");

?>
<html>
	  <body>
	  <table border=1 align='center' width=800 cellpadding=20 cellspacing=0>
	 <tr>
	<td colspan=2><h1>Delete Record</h1>
	</td>
	</tr>

<tr>
<td>
<ul>
<a href='View.php'><li>View Record</li></a>
<a href='Add.php'><li>Add Record</li></a>	
<a href='Edit.php'><li>Edit Record</li></a>
<a href='Delete.php'><li>Delete Record</li></a>
</u>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</td>


<td>
<table border=2 width=550 cellpadding=7 cellspacing=0>

<?php

	for($x=0;$x<=100;$x++)
		{
			if($_POST[del.$x])
			{
			$delete = mysql_query("DELETE FROM resume WHERE id=$x");
			echo "record has been deleted";
			}
			}

echo "<table border=0 align='center' width=>
<form method='post' action='View.php'>
<tr>
<td><center>Name</center></td>
<td><center>Age</center></td>
<td><center>Sex</center></td>
<td><center>Mobile</center></td>
<td><center>Action</center></td>
</tr>";

while($data=mysql_fetch_array($sel))
		{
			echo "
			<tr>
			<td><center>$data[name]</center></td>
			<td><center>$data[age]</center></td>
			<td><center>$data[sex]</center></td>
			<td><center>$data[mobile]</center></td>
			<td><input type='submit' value='Remove' name='del$data[id]'></td>
			</tr>";
		}






echo "</table>";
?>


<tr>
<td colspan=2 align='center'>
Copyright&copy;2011,
</tr>
</td>
</table>
</body>
</html>

Recommended Answers

All 6 Replies

DELETE the record before you SELECT it, otherwise it will appear in the result list of the select (line 4) before your delete in line 42 kills it.

DELETE the record before you SELECT it, otherwise it will appear in the result list of the select (line 4) before your delete in line 42 kills it.

I think u did not understand...i mean this code is working as i said before i can delete record normally but u need to click twice the DELETE button...what i want is 1 click then poof delete record...sorry sir i did not get what your point here peace ^^

You need to click twice because your action sequence is wrong. Change it and you will have to click once only.

totally agree with smantscheff

u use select sql command to query the resume table @ line 4
then delete record in the resume table @ line 42
and @line57 u display the result($sel) that u get from select sql command @line 4

actually what happen in here is when u click the Delete Button record is delete successfuly. but u display the result(which is contain in $sel variable ) that u created in line4 .

u have to delete the record before the select query or query after the delete

hope this will help u :)

use this script

<?php
    $con = mysql_connect("localhost","root","");
    $sql = mysql_select_db("luweegee",$con);
   
     
    ?>
    <html>
    <body>
    <table border=1 align='center' width=800 cellpadding=20 cellspacing=0>
    <tr>
    <td colspan=2><h1>Delete Record</h1>
    </td>
    </tr>
     
    <tr>
    <td>
    <ul>
    <a href='View.php'><li>View Record</li></a>
    <a href='Add.php'><li>Add Record</li></a>
    <a href='Edit.php'><li>Edit Record</li></a>
    <a href='Delete.php'><li>Delete Record</li></a>
    </u>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    </td>
     
     
    <td>
    <table border=2 width=550 cellpadding=7 cellspacing=0>
     
    <?php
     
    for($x=0;$x<=100;$x++)
    {
    if($_POST[del.$x])
    {
    $delete = mysql_query("DELETE FROM resume WHERE id=$x");
    echo "record has been deleted";
    }
    }
     
    echo "<table border=0 align='center' width=>
    <form method='post' action='View.php'>
    <tr>
    <td><center>Name</center></td>
    <td><center>Age</center></td>
    <td><center>Sex</center></td>
    <td><center>Mobile</center></td>
    <td><center>Action</center></td>
    </tr>";


    $sel = mysql_query("SELECT * FROM resume");
     
    while($data=mysql_fetch_array($sel))
    {
    echo "
    <tr>
    <td><center>$data[name]</center></td>
    <td><center>$data[age]</center></td>
    <td><center>$data[sex]</center></td>
    <td><center>$data[mobile]</center></td>
    <td><input type='submit' value='Remove' name='del$data[id]'></td>
    </tr>";
    }
     
     
     
     
     
     
    echo "</table>";
    ?>
     
     
    <tr>
    <td colspan=2 align='center'>
    Copyright&copy;2011,
    </tr>
    </td>
    </table>
    </body>
    </html>

use this script

<?php
    $con = mysql_connect("localhost","root","");
    $sql = mysql_select_db("luweegee",$con);
   
     
    ?>
    <html>
    <body>
    <table border=1 align='center' width=800 cellpadding=20 cellspacing=0>
    <tr>
    <td colspan=2><h1>Delete Record</h1>
    </td>
    </tr>
     
    <tr>
    <td>
    <ul>
    <a href='View.php'><li>View Record</li></a>
    <a href='Add.php'><li>Add Record</li></a>
    <a href='Edit.php'><li>Edit Record</li></a>
    <a href='Delete.php'><li>Delete Record</li></a>
    </u>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    </td>
     
     
    <td>
    <table border=2 width=550 cellpadding=7 cellspacing=0>
     
    <?php
     
    for($x=0;$x<=100;$x++)
    {
    if($_POST[del.$x])
    {
    $delete = mysql_query("DELETE FROM resume WHERE id=$x");
    echo "record has been deleted";
    }
    }
     
    echo "<table border=0 align='center' width=>
    <form method='post' action='View.php'>
    <tr>
    <td><center>Name</center></td>
    <td><center>Age</center></td>
    <td><center>Sex</center></td>
    <td><center>Mobile</center></td>
    <td><center>Action</center></td>
    </tr>";


    $sel = mysql_query("SELECT * FROM resume");
     
    while($data=mysql_fetch_array($sel))
    {
    echo "
    <tr>
    <td><center>$data[name]</center></td>
    <td><center>$data[age]</center></td>
    <td><center>$data[sex]</center></td>
    <td><center>$data[mobile]</center></td>
    <td><input type='submit' value='Remove' name='del$data[id]'></td>
    </tr>";
    }
     
     
     
     
     
     
    echo "</table>";
    ?>
     
     
    <tr>
    <td colspan=2 align='center'>
    Copyright&copy;2011,
    </tr>
    </td>
    </table>
    </body>
    </html>

Thanks sir y2kshane this code is really work... more people need your help cheers :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.