issouf Posted March 12, 2008 Share Posted March 12, 2008 Hi guys! I have a page (PAGE1) that displays data from my database. I want to be able to delete using an hyperlink called DELETE after PAGE1 has executed and all the data from database. PAGE2 contains the set of codes that does the actual deletion. I am using Session, but any time I click on DELETE only the data on the last row is deleted. I have been on this for more than a week.Pls help. ----------------------PAGE1------------------------------- <? start_session() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Display Addresses </title> </head> <body> <form name="Myform" action="delete.php" method="POST"> <table borders="1" rules="all"> <?PHP $db= mysql_connect("localhost","root","passwd")or die (mysql_error()); mysql_select_db("myaddress", $db) or die (mysql_error()); $result=mysql_query('select * from address'); ?> <tr bgcolor='red'><th>Id</th><th>Name</th><th>Address</th><th>Delete</th></tr> <?PHP while ($data=mysql_fetch_array($result)) { ?> <tr> <td align ="center"> <?PHP echo $data['id']; ?></td> <td align ="center"> <?PHP echo $data['name']; ?></td> <td align ="center"><?PHP echo $data['address']; ?></td> <td> <a href="page2.php">Delete</a> </td> </tr> <?PHP }?> </table> </form> </body> </html> ----------------------------END OF PAGE1-------------------------------------------- ----------------------------PAGE2---------------------------------------------------- <? start_session() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Delete </title> </head> <body> <?PHP $db= mysql_connect("localhost","root","issouf"); mysql_select_db("myaddress", $db); $sql="delete from address where id=$_SESSION[id]"; if ($result=mysql_query($sql,$db)) { echo "<h1>SUCCESSFUL</h1>"; } else { echo "ERROR IN DELETING"; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 12, 2008 Share Posted March 12, 2008 $id_to_delete = $_SESSION['id']; $sql="DELETE FROM `address` WHERE `id`='$id'"; Or if you like the one lined code $sql="DELETE FROM `address` WHERE `id`='{$_SESSION['id']}'"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.