Jump to content


Photo

Deleting a row in a Table


  • Please log in to reply
3 replies to this topic

#1 gladiator83x

gladiator83x
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 14 July 2006 - 07:49 PM

Hi All,

I was just wondering if anyone could help me troubleshoot this error that I keep receiving. I am trying to delete something in a table if it is  already in there, and I keep receiving an error message that states that something is wrong with my syntax. I changed it around several times, but still nothing. Any suggestions?


$res=mysql_query("select * from End_Review");
if(mysql_num_rows($res)==0) echo "there is no data in table..";
if (mysql_num_rows($res)!=0)
{

for($i=0;$i<mysql_num_rows($res);$i++)
{
$row=mysql_fetch_assoc($res);

}
// $row is an array of titles
mysql_query("DELETE FROM End_Review WHERE $title==$row[topic_title]")
or die(mysql_error());
}


If it helps, this is how I input data into this table--it works fine.

mysql_query("INSERT INTO End_Review
(id,topic_title, date) VALUES('','$title','$test_date' ) ")
or die(mysql_error());




#2 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 14 July 2006 - 07:57 PM

I think that topic_title in $row[topic_title] should be in quotes.

mysql_query("DELETE FROM End_Review WHERE $title==$row[topic_title]")

Look at the "MySQL Related" section in PHP Coding tips for ideas on how to troubleshoot your MySQL query.
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#3 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 14 July 2006 - 08:00 PM

$query = "delete from End_review where topic_title = ".$title;
mysql_query($query) or die(mysql_error());

you need to compair it to a field name.....
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 July 2006 - 08:50 PM

agreed about needing to compare an actual field with something.  jvroth fixed the actual issue without pointing it out - comparison in MySQL takes place with one equal sign, not two.  have a look in the MySQL manual at the comparison operators.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users