Jump to content

Error in my syntax


graham23s

Recommended Posts

Hi Guys,

 

i'm getting an error in my syntax here but it looks fine to me the error is:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id`='4'' at line 1

 

heres the code:

 

     $query2 = "SELECT `views` FROM `uploaded` WHERE `id`='$id'";
     $result2 = mysql_query($query2) or die (mysql_error());
     $row = mysql_fetch_array($result2) or die(mysql_error());
     
     // put views in  avariable...///////////////////////////////////////////////////////
     $views = $row['views'];
     
     // if have no counter value set counter value to 1...///////////////////////////////
     if(empty($views)) {
     
     $views = 1;
     
     $query3 = "INSERT INTO `uploaded` (`views`) VALUES ('$views') WHERE `id`='$id'";
     $result3 = mysql_query($query3) or die (mysql_error());
     
     }
     
     // increment the views by 1...//////////////////////////////////////////////////////
     $add_another_1 = $views + 1;
     
     $query4 = "UPDATE `uploaded` SET `views`='$add_another_1' WHERE `id`='$id'";
     $result4 = mysql_query($query4) or die (mysql_error());  

 

it doesn't say on what line but it all looks ok!

 

cheers guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/51567-error-in-my-syntax/
Share on other sites

You can't use the WHERE-Clause in INSERT INTO commands:

your wrong code:

$query3 = "INSERT INTO `uploaded` (`views`) VALUES ('$views') WHERE `id`='$id'";

right:

$query3 = "INSERT INTO `uploaded` (`views`) VALUES ('$views')";

or:

$query3 = "INSERT INTO `uploaded` SET `views` = '$views'";

Link to comment
https://forums.phpfreaks.com/topic/51567-error-in-my-syntax/#findComment-253939
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.