Jump to content

Archived

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

gladiator83x

Deleting a row in a Table

Recommended Posts

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());


Share this post


Link to post
Share on other sites
I think that topic_title in $row[topic_title] should be in quotes.

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

Look at the "MySQL Related" section in [url=http://dptr1988.mooo.com/php_tips.php]PHP Coding tips[/url] for ideas on how to troubleshoot your MySQL query.

Share this post


Link to post
Share on other sites
[code]
$query = "delete from End_review where topic_title = ".$title;
mysql_query($query) or die(mysql_error());
[/code]

you need to compair it to a field name.....

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.