marcus Posted November 24, 2006 Share Posted November 24, 2006 Ok, I'm trying to make something that the administrator can delete a certain news id by clicking the Delete $id button. Below is my code. I get no errors, it just doesn't work.[code]<?php$pg = $_GET[pg];if(!$pg){$pg = 1;};$amount = "$pg * 12";if(!$act){?><table border=0 cellspacing=2 cellpadding=2><tr><td colspan=4 align=right><h3>Delete News</h3><tr><td colspan=4> <tr><td class=cA>ID<td class=cA>Title<td class=cA>Message<td class=cA>Author<?php$find = "SELECT * FROM news ORDER BY `id` ASC";$gofi = mysql_query($find);while($row1 = mysql_fetch_assoc($gofi)){echo "<tr><td>$row1[id]<td>$row1[title]<td>$row1[body]<td>$row1[poster]<tr><td colspan=4 align=right><form name=delete$row1[id] method=post action='".$PHP_SELF."'><input type=hidden name=delid value=$row1[id]><input type=submit value='Delete ".$row1[id]."'></form>";}mysql_free_result($gofi);echo "</table>";};?><?phpif($act == delid){$delid = $_POST[delid];$del = "DELETE FROM `news` WHERE id=$delid";$delgo = mysql_query($del) or die(mysql_error());echo "News ID $delid deleted";};?>[/code] Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/ Share on other sites More sharing options...
The Little Guy Posted November 24, 2006 Share Posted November 24, 2006 Try changing this:[code]$del = "DELETE FROM `news` WHERE id=$delid";[/code]To this:[code]$del = "DELETE * FROM `news` WHERE id=$delid";[/code] Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129468 Share on other sites More sharing options...
marcus Posted November 24, 2006 Author Share Posted November 24, 2006 It works now :) Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129470 Share on other sites More sharing options...
btherl Posted November 24, 2006 Share Posted November 24, 2006 "DELETE *"? What does that do? That's like no sql I've ever seen :) Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129474 Share on other sites More sharing options...
pikemsu28 Posted November 24, 2006 Share Posted November 24, 2006 "DELETE *" deletes the entire record that is associated with the ID. If your table contained three fields name_id, first_name, last_name:name_id first_name last_name1 Sam Fisher2 Bob Johnson3 Michael Jordanif you wanted to delete Bob Johnson by name_id, "Delete * from table where name_id = 2" This lets sql know to delete the entire row associated with name_id = 2. * basically means 'SELECT ALL'. it is short hand for this delete statement, "Delete name_id, first_name, last_name from table where name_id = 2" Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129478 Share on other sites More sharing options...
marcus Posted November 24, 2006 Author Share Posted November 24, 2006 I had it fixed when I locked it. Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129485 Share on other sites More sharing options...
JasonLewis Posted November 24, 2006 Share Posted November 24, 2006 i never use DELETE * i just use DELETE FROM and it works fine for me. Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129486 Share on other sites More sharing options...
btherl Posted November 24, 2006 Share Posted November 24, 2006 I looked it up..http://dev.mysql.com/doc/refman/5.0/en/delete.htmlIt seems that DELETE t1, t2 syntax which operates on tables rather than columns. It's a mysql extension. "DELETE *" is not mentioned in the documentation, so I would recommend not using it. "DELETE FROM table WHERE condition" is the usual syntax. Link to comment https://forums.phpfreaks.com/topic/28306-mysql-delete-help/#findComment-129489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.