HughbertD Posted December 11, 2007 Share Posted December 11, 2007 Hi, I am looping information from my database into an html table, and have an "Edit" and "Delete" link at the end of each row. When I click delete, it does not do anything, but also, the $id value does not appear in the url. What am I doing wrong? I think it has something to do with $GET, am I right? Here is my code (minus some CSS bits and pieces): <?php $usr = "root"; $pwd = "michael"; $db = "jostark"; $host = "localhost"; $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } mysql_select_db("jostark", $cid); if ($task=="del") { $SQL = " DELETE FROM manager "; $SQL = $SQL . " WHERE managerID = $id "; mysql_query($SQL, $cid); } echo("$id"); ?> <?php $SQL = " select * from manager, placement where manager.companyID = placement.companyID;"; $retid = mysql_query($SQL, $cid); if (!$retid) { echo( mysql_error()); } else { echo "<P><TABLE CELLPADDING=4>\n"; ?> <tr> <td>Name</td> <td>Company</td> <td>Email</td> </tr> <?php while ($row = mysql_fetch_array($retid)) { $firstName = $row["manFirstName"]; $lastName = $row["manLastName"]; $company = $row["compName"]; $email = $row["manEmail"]; $id = $row["id"]; echo ("<TR>"); echo ("<TD>$firstName $lastName</TD>\n"); echo ("<TD>$company</TD>\n"); echo ("<TD>$email</TD>\n"); echo ("<TD><A HREF=\"manageedit.php?id=$id\">Edit</A></TD>"); echo ("<TD><A HREF=\"displayManager.php?id=$id&task=del\">Delete</A></TD>"); echo ("</TR>"); } echo ("</TABLE>"); } ?> Thank you to anyone that can help out, this has been driving me nuts! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2007 Share Posted December 11, 2007 well if its coming from get add this line on top of each code $id = $_GET['id']; Quote Link to comment Share on other sites More sharing options...
HughbertD Posted December 11, 2007 Author Share Posted December 11, 2007 I now have the variable displaying in the url, like so: http://localhost/joStark/css/displayManager.php?id=3&task=del It was due to me having the field name for the managerID wrong in the table However, it still does not perform a delete I am not using a POST for this, should I be? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2007 Share Posted December 11, 2007 also the same should be for task $task = $_GET['task']; Quote Link to comment Share on other sites More sharing options...
HughbertD Posted December 11, 2007 Author Share Posted December 11, 2007 I am confused I see from the url that there is a value for id and task, does this mean I do not require a GET? Do I need to use the get in the del task statement? Do I need to use a POST as well? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 11, 2007 Share Posted December 11, 2007 you use $_get to obtain information out of a URL. For example www.adam.co.uk?adam=4 <?php $adam = $_get['adam']; $echo $adam; ?> this will return 4. $_Post gets information from a form. This information is sent to the form directly. Quote Link to comment Share on other sites More sharing options...
HughbertD Posted December 11, 2007 Author Share Posted December 11, 2007 I think I understand so I put: if ($task=="del") { $id = $_GET['id']; $SQL = " DELETE FROM manager "; $SQL = $SQL . " WHERE managerID = $id "; mysql_query($SQL, $cid) or die (mysql_error()); } This extracts the id= part from my url, but I don't think it is actually doing "del" at all. Is this why I need to use a $GET on the $TASK too? I have the $task at the top of the code, does this make a difference? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 11, 2007 Share Posted December 11, 2007 when you echo $id do you get anything? edit.... also post your current code Quote Link to comment Share on other sites More sharing options...
HughbertD Posted December 11, 2007 Author Share Posted December 11, 2007 I got it! I was putting the GET for the task inside the If statement of the task function. So I guess it never got around to getting it out the url. Thanks Adam and thanks Rajiv! I appreciate the help P.S. No, I put in "echo $id;" underneath mysql_query and it doesn't return anytthing., it appears to be working though. Is this something to worry about? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 11, 2007 Share Posted December 11, 2007 if you set $id to = $_GET['id'] it should echo out. Post the code. 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.