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] Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
marcus Posted November 24, 2006 Author Share Posted November 24, 2006 It works now :) Quote Link to comment 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 :) Quote Link to comment 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" Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. 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.