0riole Posted October 4, 2005 Share Posted October 4, 2005 The script below, should from my BASIC knowledge, retrieve the records stored in the table "venues" display the value "name" along with a link to modify the record on a separate page (manage_edit.php) or delete the record and reload this page (manage.php). The problem is that it dose not delete just reloads. Where have I gone wrong? Thanks, Chris ----------------------------------------------------------------- <? $usr = "--username--"; $pwd = "--password--"; $db = "--MySQL_Database--"; $host = "localhost"; //Setup Veribales $id = $_POST['id']; $name = $_POST['name']; $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } if ($task=="del") { $sql = "DELETE FROM venues WHERE id = '$id'"; mysql_db_query($db, $sql, $cid); } ?> <HTML> <HEAD> <TITLE>Manage Links</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" > <H1>Edit Links</H1> <? $sql = " SELECT * FROM venues "; $retid = mysql_db_query($db, $sql, $cid); if (!$retid) { echo( mysql_error()); } else { echo ("<P><TABLE CELLPADDING=4>\n"); while ($row = mysql_fetch_array($retid)) { $name = $row['name']; $id = $row['id']; echo ("<TR>"); echo ("<TD>$name</TD>\n"); echo ("<TD><A HREF=\"manage_edit.php?id=$id \">Edit</A></TD>"); echo ("<TD><A HREF=\"manage.php?id=$id&task=del \">Delete</A></TD>"); echo ("</TR>"); } echo ("</TABLE>"); } ?> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/ Share on other sites More sharing options...
Cook Posted October 4, 2005 Share Posted October 4, 2005 You connect to your db server, but you don't select a db to work with. Try adding a mysql_select_db() call right after your mysql_connect() call. :edit: my bad, didn't see you were using mysql_db_query() rather than mysql_query(), let me have another look at this code then... Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8626 Share on other sites More sharing options...
Cook Posted October 4, 2005 Share Posted October 4, 2005 Ok, think I got it, try adding this right after your $id and $name init at the beginning of your script: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$task = $_GET[\'task\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8627 Share on other sites More sharing options...
0riole Posted October 4, 2005 Author Share Posted October 4, 2005 Ok, think I got it, try adding this right after your $id and $name init at the beginning of your script: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$task = $_GET[\'task\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] 302540[/snapback] Tried that, also suggested by a user on an Australian forum, but still no good also had suggested putting in the id and name in that querry, but not shure how to go about this Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8628 Share on other sites More sharing options...
Cook Posted October 4, 2005 Share Posted October 4, 2005 Your $id is also given to your script via the GET method, not the POST method, so change this line: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$id = $_POST[\'id\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] to this: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$id = $_GET[\'id\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] And this line: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$name = $_POST[\'name\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] appears to be pretty useless. Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8629 Share on other sites More sharing options...
0riole Posted October 4, 2005 Author Share Posted October 4, 2005 Your $id is also given to your script via the GET method, not the POST method, so change this line: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$id = $_POST[\'id\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] to this: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$id = $_POST[\'id\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] And this line: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$id = $_POST[\'id\'];[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] appears to be pretty useless. 302543[/snapback] OK Done all that and still no joy, what else could be going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8630 Share on other sites More sharing options...
Cook Posted October 4, 2005 Share Posted October 4, 2005 Suggest you post the current version of your script. Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8631 Share on other sites More sharing options...
0riole Posted October 4, 2005 Author Share Posted October 4, 2005 Suggest you post the current version of your script. 302547[/snapback] <? $usr = "username"; $pwd = "password"; $db = "database"; $host = "localhost"; //Setup Veribales $id = $_GET['id']; $task = $_GET['task']; $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } if ($task=="del") { $sql = "DELETE FROM venues WHERE id = '$id' name='$name'"; mysql_db_query($db, $sql, $cid); } ?> <HTML> <HEAD> <TITLE>Manage Links</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" > <H1>Edit Links</H1> <? $sql = " SELECT * FROM venues "; $retid = mysql_db_query($db, $sql, $cid); if (!$retid) { echo( mysql_error()); } else { echo ("<P><TABLE CELLPADDING=4>\n"); while ($row = mysql_fetch_array($retid)) { $name = $row['name']; $id = $row['id']; echo ("<TR>"); echo ("<TD>$name</TD>\n"); echo ("<TD><A HREF=\"manage_edit.php?id=$id\">Edit</A></TD>"); echo ("<TD><A HREF=\"manage.php?id=$id&task=del\">Delete</A></TD>"); echo ("</TR>"); } echo ("</TABLE>"); } ?> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8632 Share on other sites More sharing options...
Cook Posted October 4, 2005 Share Posted October 4, 2005 Now your delete query is not well formed. Do you need the name condition? If so, your need to put an and in between the two tests. But then, where does your $name var come from? $sql = "DELETE FROM venues WHERE id = '$id' name='$name'"; Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8633 Share on other sites More sharing options...
0riole Posted October 4, 2005 Author Share Posted October 4, 2005 Now your delete query is not well formed. Do you need the name condition? If so, your need to put an and in between the two tests. But then, where does your $name var come from? $sql = "DELETE FROM venues WHERE id = '$id' name='$name'"; 302551[/snapback] Thanks, All happy now Quote Link to comment https://forums.phpfreaks.com/topic/2606-deleting-records/#findComment-8634 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.