Jump to content

Deleting entries?


Turgay

Recommended Posts

hi every1,

just wondering if anybody could help me, i have made a simple forum which consist of two tables:

Forum_question.mysql:
`id` int(4) NOT NULL auto_increment,
`topic` varchar(255) NOT NULL default '',
`detail` longtext NOT NULL,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`datetime` varchar(25) NOT NULL default '',
`view` int(4) NOT NULL default '0',
`reply` int(4) NOT NULL default '0',
PRIMARY KEY (`id`)

forum_answer.mysql
`question_id` int(4) NOT NULL default '0',
`a_id` int(4) NOT NULL default '0',
`a_name` varchar(65) NOT NULL default '',
`a_email` varchar(65) NOT NULL default '',
`a_answer` longtext NOT NULL,
`a_datetime` varchar(25) NOT NULL default '',
`a_delete` varchar(25) NOT NULL default '',
KEY `a_id` (`a_id`)

once user post it stores the topic area in "forum_question" and answers to the topic are made to forum_answer table. Iam trying to delete entries from these table using the script:

//If cmd is not hit
if(!isset($cmd))
{
  //display all the news
  $result = mysql_query("select * from forum_question");
 
  //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["topic"];//take out the title
      $id=$r["id"];//take out the id
   
      echo "<a href='edit.php?cmd=delete&id=$id'>$title - Delete</a>";
      echo "<br>";
    }
}
?>

<?
if($cmd=="delete")
{
  $del_forum_question_sql ="DELETE * FROM forum_question WHERE id=$id";
    $result = mysql_query($sql);
    echo "Row deleted!";
    echo "<br><br>";
    echo "<a href='edit.php'>DELETE ANOTHER</a>";
    echo "<br><br>";
    echo "<a href='main_forum.php'>MAIN FORUM</a>";
}
?>

there is no error message it just wont do anything...can anybody suggest another way to delete topics one by one??

Thanks
Link to comment
https://forums.phpfreaks.com/topic/29221-deleting-entries/
Share on other sites

This is where your problem is:
[code]$del_forum_question_sql ="DELETE * FROM forum_question WHERE id=$id";
    $result = mysql_query($sql);[/code]

$del_forum_question_sql is your sql statement. It needs to be in mysql_query.

[code]$del_forum_question_sql ="DELETE * FROM forum_question WHERE id=$id";
    mysql_query($del_forum_question_sql);[/code]
Link to comment
https://forums.phpfreaks.com/topic/29221-deleting-entries/#findComment-133978
Share on other sites

should be this

[code]$sql="DELETE * FROM forum_question WHERE id='$id'";
mysql_query($sql);[/code]

As long as $id is set and there is a corresponding entry in the table that should work. Also check your syntax for case errors, if the column is ID in the table and you say WHERE id= it won't work.
Link to comment
https://forums.phpfreaks.com/topic/29221-deleting-entries/#findComment-134169
Share on other sites

[quote author=jcbarr link=topic=117107.msg477753#msg477753 date=1165112449]
Also you aren't closing any of your anchor tags, what's with the [/url] isn't that BBCode? Why would you be mixing the two?
[/quote]

No idea why the anchor tag is placed like that here sorry it is </a> on the actual script, damn it wont delete any entries still =( or maybe its me lol iam a newb to all this, its just it wont display any error messages, when i select the topic to delete it displays "row deleted" as it should but when i view the actual forum its still there..
Link to comment
https://forums.phpfreaks.com/topic/29221-deleting-entries/#findComment-134262
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.