Jump to content

Mysql Delete Help


marcus

Recommended Posts

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>&nbsp;
<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>";
};
?>
<?php
if($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

"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_name
1                    Sam              Fisher
2                    Bob                Johnson
3                    Michael          Jordan

if 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

I looked it up..

http://dev.mysql.com/doc/refman/5.0/en/delete.html

It 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.