PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Oct 28, 2020 5:40 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jul 19, 2010 5:48 am 
Offline
Forum Newbie

Joined: Mon Jul 19, 2010 5:41 am
Posts: 1
Hello, newby question here. I have a code showing comments, but I can't figure out a way to make a delete button for them, here's my code:
Syntax: [ Download ] [ Hide ]
         $result = mysql_query("SELECT * FROM comment ORDER BY P_Id DESC;");
                            while($row = mysql_fetch_array($result)) {
                            $delete = mysql_query("delete from comment where P_Id = $row[P_Id]");
                            echo "<a href='?delete&id=$row[P_Id]'>[x]</a> <span class='name'>" . $row['name'] . "</span>: " . $row['comment'] . "(" . $row['P_Id'] . ")" . "<br/><br/>"; }
 


so the thing is - all my comments are being deleted on page refresh and I can't have more than one comment at a time, but with this source I can delete that one. So can you give me some hints or maybe the exact code even, if it's not too much to ask? Thanks.


Top
 Profile  
 
PostPosted: Mon Jul 19, 2010 11:56 am 
Offline
Forum Regular

Joined: Thu Dec 10, 2009 7:27 pm
Posts: 675
You need single quotes around your variable:

Syntax: [ Download ] [ Hide ]
mysql_query("delete from comment where P_Id = '$row[P_Id]'");


To troubleshoot queries, you can also do this:

Syntax: [ Download ] [ Hide ]
mysql_query("delete from comment where P_Id = $row[P_Id]") or die(mysql_error());


Then if the query fails, it will give you some idea of why.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group