Jump to content

Using hyperlink to delete in a database


issouf

Recommended Posts

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>

 

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.

Guest
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.