Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.