Celcius Posted April 2, 2010 Share Posted April 2, 2010 I am trying to do a query to populate a list (or table, or whatever). Then if you click on them, they get deleted from their MySQL table. I have 11 or so tables I want to do for this, but here is the CREATE TABLE statement for one of them. CREATE TABLE Airline( name VARCHAR(20), code CHAR(5) PRIMARY KEY, website VARCHAR(40) ); So I want to populate a list with th entries of this table, and then when you click on a delete button beside the row, it deletes that tuple. I found this script, but it's not working. <?php if(!isset($cmd)) { //display all the news $result = mysql_query("SELECT * FROM Airline ORDER BY name"); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the enws $title=$r["name"];//take out the title $code=$r["code"];//take out the id echo "<a href='delete.php?cmd=delete&code=$code'>$title - Delete</a>"; echo "<br>"; } } ?> <?php if($cmd=="delete") { $sql = "DELETE FROM Airline WHERE code='$code'"; $result = mysql_query($sql); echo "Row deleted!"; } ?> Any ideas on a better script or how to fix that one? Link to comment https://forums.phpfreaks.com/topic/197387-populate-list-and-delete-rows-phpmysql/ Share on other sites More sharing options...
mikesta707 Posted April 2, 2010 Share Posted April 2, 2010 what version of php do you have? that seems to rely on an old setting that has become deprecated. instead of $cmd try replacing occurrences of that with $_GET['cmd'] btw the equivalent of lists in PHP are known as arrays. I don't believe there is a data structure in PHP that is like a tuple though. Link to comment https://forums.phpfreaks.com/topic/197387-populate-list-and-delete-rows-phpmysql/#findComment-1036025 Share on other sites More sharing options...
Celcius Posted April 2, 2010 Author Share Posted April 2, 2010 Like this? <?php if(!isset($_GET['cmd'])) { //display all the news $result = mysql_query("SELECT * FROM Airline ORDER BY name"); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the enws $title=$r["name"];//take out the title $code=$r["code"];//take out the id echo "<a href='delete.php?cmd=delete&code=$code'>$title - Delete</a>"; echo "<br>"; } } ?> <?php if($_GET['cmd']=="delete") { $sql = "DELETE FROM Airline WHERE code='$code'"; $result = mysql_query($sql); echo "Row deleted!"; } ?> Or am I just being dense? Because that doesn't seem to have helped. Link to comment https://forums.phpfreaks.com/topic/197387-populate-list-and-delete-rows-phpmysql/#findComment-1036027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.