Jump to content

Delete rows from while statment


nezbo

Recommended Posts

Hi all

 

I have this code and i want to beable to when i click the delete link to delete the row that is selected in the database?

 

Any help please?

 

$result = mysql_query("SELECT * FROM person ORDER BY UserName ASC");

echo "<table border=1 align=center>";

echo "<tr><td colspan=8 align=center><h2>All users registered with the system.</h2><tr><td>";

while ($row = mysql_fetch_array($result))

{

echo "<tr><td align=left><a href=editUser.php?user_identifier=$row[CallID] >$row[CallID] </a>" .

"</td><td align=left>" . $row['UserName'] .

"</td><td align=left>" . $row['FullName'] .

"</td><td align=left>" . $row['EmailAddress'] .

"</td><td align=left>" . $row['ContactNumber'] . 

"</td><td align=left>" . $row['UserLevel'] .

"</td><td align=left> <a href=#>Delete</a>" . "</td></tr>";

}

echo "</table>";

 

Neil

Link to comment
Share on other sites

Well im guesing that your 'CallID' field is a unique field? If so, just pass that into the query string, as you do for your editUser.php page, and delete the row:

 

<?php
$id = $_GET['CallID'];
mysql_query("DELETE FROM `person` WHERE `CallID`='$id'") or die(mysql_error());
?>

Link to comment
Share on other sites

cool cheers

 

does this mean i need to creat a form type of thing to instrd of using a <a href.... ?

 

 

 

Well im guesing that your 'CallID' field is a unique field? If so, just pass that into the query string, as you do for your editUser.php page, and delete the row:

 

<?php
$id = $_GET['CallID'];
mysql_query("DELETE FROM `person` WHERE `CallID`='$id'") or die(mysql_error());
?>

Link to comment
Share on other sites

No not at all. Get variables are passed to a page in the URL. If you specify the form method as get, all it actually does it put the contents of the form in the url.

 

You would make your links something like:

 

echo "<a href='deleteuser.php?id=$row[CallID]'>$row[CallID]</a>";

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.