Forum Moderators: coopster

Message Too Old, No Replies

Using hyperlinks to invoke PHP

         

technossomy

2:56 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Suppose I have an inventory list ($inventory), consisting of unique parts only, which have been fetched from a database ($db), and I want to display something like this:

function deletepart($part) {
$q = "DELETE FROM inventory WHERE part = '" . $part . "'";
$db->execute($q);
}

foreach($inventory as $i)
$str .= "<tr><td>" . $i['part'] . "</td><td><a href=\"deletepart(" . $i['part'] . ")\">delete this part</a></td></tr>\n";

echo "<table>\n" . $str . "</table>\n";

The problem of course is in the <a href>-tag: it will lead to a new page, but I only want to manipulate the database $db. So without using buttons, how can I make the hyperlink act as a button? I am happy to wrap the table in a form, as long as it does not contain any Javascript.

Thanks in advance

Tech

bomburmusicmallet

3:09 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Hi Tech,

Why can't you make the link the same page as the page you are listing the delete links and send the ID for the part to be deleted as a parameter. Something like (check the code for the link):

function deletepart($part) {
$q = "DELETE FROM inventory WHERE part = '" . $part . "'";
$db->execute($q);
}

if($_GET['part'])
{deletepart($_GET['part']);}

foreach($inventory as $i)
$str .= "<tr><td>" . $i['part'] . "</td><td><a href=\"deletepart.php?part=" . $i['part'] . "\">delete this part</a></td></tr>\n";

echo "<table>\n" . $str . "</table>\n";

HTH, Jenny

technossomy

11:25 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Thanks for your input. I have successfully implemented your suggestion.