dub_beat Posted November 9, 2009 Share Posted November 9, 2009 Hi, I'm having trouble figuring out how to do the following. I make a mysql request to give me all of the entries in a table. For each result I add a new html table row to my form with the results data and a "delete" of type submit. I want to know if it possible to assign the primary key value of each result entry to each delete button so that when the delete button is hit the primary key of the entry is sent to a script to remove that entry from the database table. So if I had 3 results whose primary keys where 1, 2 and3 and I clicked on delete button 2 I would send "2" to my delete script. I'm not sure if I'm going about this the right way? I'm kinda in the early stage of learning PHP so any help or advice would very well recieved. Thanks! while ($row = mysql_fetch_array ($result, MYSQL_NUM)) { echo " <tr> <td align=\"left\">{$row[0]}</td> //$row[0] contains the primary key <td align=\"left\">{$row[2]}</td> <td align=\"left\"><input type=\"submit\" name=\"delete\" value=\"$row[0]\"></td> </tr>\n"; } if (isset($_POST['delete'])) { // my delete function with the correct primary key to use } Quote Link to comment https://forums.phpfreaks.com/topic/180910-beginner-multiple-submit-button-with-one-form/ Share on other sites More sharing options...
taquitosensei Posted November 10, 2009 Share Posted November 10, 2009 instead of a delete button you could do a link with the id and an image. echo "<td align='left'>".$row[0]."</td> <td align='left'>".$row[2]."</td> <td align='left'><a href='?action=delete&id=".$row[0]."'><img src='your_delete_icon.gif' border='0'></a></td> then at the beginning of your page check for it if(isset($_GET['action']) && $_GET['action']=="delete") { // your delete function here would use $_GET['id'] } Quote Link to comment https://forums.phpfreaks.com/topic/180910-beginner-multiple-submit-button-with-one-form/#findComment-954465 Share on other sites More sharing options...
dub_beat Posted November 10, 2009 Author Share Posted November 10, 2009 Hey good thinking. It was beginning to dawn on me that maybe I was using the wrong html component for the job. Thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/180910-beginner-multiple-submit-button-with-one-form/#findComment-954467 Share on other sites More sharing options...
Dorky Posted November 10, 2009 Share Posted November 10, 2009 i use links for this as well but be sure to add && isset($_SESSION['user']) replace user with the key of logged in users. otherwise anyone can just run links and delete whatever. Quote Link to comment https://forums.phpfreaks.com/topic/180910-beginner-multiple-submit-button-with-one-form/#findComment-954469 Share on other sites More sharing options...
dub_beat Posted November 10, 2009 Author Share Posted November 10, 2009 Thanks for the tip! Much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/180910-beginner-multiple-submit-button-with-one-form/#findComment-954470 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.