gladiator83x Posted July 14, 2006 Share Posted July 14, 2006 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()); Quote Link to comment https://forums.phpfreaks.com/topic/14609-deleting-a-row-in-a-table/ Share on other sites More sharing options...
dptr1988 Posted July 14, 2006 Share Posted July 14, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14609-deleting-a-row-in-a-table/#findComment-58070 Share on other sites More sharing options...
jvrothjr Posted July 14, 2006 Share Posted July 14, 2006 [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..... Quote Link to comment https://forums.phpfreaks.com/topic/14609-deleting-a-row-in-a-table/#findComment-58073 Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14609-deleting-a-row-in-a-table/#findComment-58105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.