alen Posted December 15, 2006 Share Posted December 15, 2006 I made this script that's supposed to delete a row when I click on one of the news titles..I added two threads, Hello world and Test.I simply want to delete Test. But when I click on the link nothing happends.Here's the code:http://anigma.sitees.com/delete.txt Link to comment https://forums.phpfreaks.com/topic/30710-deleting-a-row/ Share on other sites More sharing options...
Eric_Ryk Posted December 15, 2006 Share Posted December 15, 2006 Normally I don't do this but its easier than typing out all the instructions:[code]<html><body><? mysql_connect("localhost","nancy","ehgxsjhn"); mysql_select_db("nancy"); if(!isset($_GET["cmd"])) { $result = mysql_query("select * from news"); while($r=mysql_fetch_array($result)) { $title=$r["title"]; $id=$r["id"]; echo "<a href='delete.php?cmd=delete&id=$id'>$title - Delete</a>"; echo "<br>"; }}if($_GET["cmd"]=="delete"){ $sql = "DELETE FROM news WHERE id=" . $_GET["id"]; $result = mysql_query($sql); echo "Row deleted!";}?></body></html>[/code]Try that out. Link to comment https://forums.phpfreaks.com/topic/30710-deleting-a-row/#findComment-141509 Share on other sites More sharing options...
btherl Posted December 15, 2006 Share Posted December 15, 2006 A good first step is to check all your mysql_() functions for errors, like this:[code=php:0]mysql_query("select * from news") or die("Error: " . mysql_error());[/code]Add something similar to mysql_connect() and mysql_select_db() Link to comment https://forums.phpfreaks.com/topic/30710-deleting-a-row/#findComment-141510 Share on other sites More sharing options...
hitman6003 Posted December 15, 2006 Share Posted December 15, 2006 change:[code]if('$cmd'=="delete")[/code]to[code]if($cmd=="delete")[/code] Link to comment https://forums.phpfreaks.com/topic/30710-deleting-a-row/#findComment-141516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.