Jump to content

Recommended Posts

I cannot get this MySQL query to work.  My code is as follows:

 

$id = mysql_real_escape_string($_GET['id']); //does return the proper value when I use echo command to display
$query = "INSERT INTO rb_notes(image_thumb) VALUES ('$thumbnail') WHERE ID LIKE $id";

 

Error I get is as follows:

 

Error in query : 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 LIKE' at line 1

 

I have tried every variation that I can think of:

 

$query = "INSERT INTO rb_notes(image_thumb) VALUES ('$thumbnail') WHERE ID LIKE '$id'";
$query = "INSERT INTO rb_notes WHERE ID LIKE '$id' (image_thumb) VALUES ('$thumbnail')";
$query = "UPDATE rb_notes(image_thumb) VALUES ('$thumbnail') WHERE ID LIKE '$id'";

 

etc etc  ... Please help!

 

 

Link to comment
https://forums.phpfreaks.com/topic/136985-solved-mysql-query-problem/
Share on other sites

Yesideez,

 

Then I guess that I have to use update instead of insert, because I have to manipulate certain rows only (as in id=6 or whatever).  At the moment I am trying this, but am having no luck:

 

$query = "UPDATE SET rb_notes image_thumb='$thumbnail' WHERE id_notes LIKE='$id'";

 

Error in query : 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 'SET rb_notes image_thumb='/uploads/thumb/200.jpg' WHERE id_notes LIKE=''' at line 1

 

Really strange, considering that if I do this:

 

echo $id;

 

I have a value returned to me.

btw...

 

Error in query : 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 'SET rb_notes SET image_thumb='/uploads/thumb/200.jpg' WHERE id_notes LIKE=''' at line 1

 

Seems like $id isn't being populated! You're passing an empty variable to the query. When changing anything in the database and you're relying on something to identify the rows targeted for modification, it's always best to check first that your conditional data contains exactly what you intend it to otherwise you can change more than you planned to!

Yesideez,

 

I know what you are saying.  I fixed up the query, and I printed the value of $id one line before the query, and it is not NULL.  I really don't know what i going on.

 

DarkWater,

 

I have NEVER seen mysql code being executed like that.  Mind you, my PHP texts are from the late nineties, I think.  Can you recommend a good site on SQL syntax in the way you have shown it?  I haven't even come across that sort of code on the internet, and God knows I have done many searches and read a few articles.

sprintf() doesn't actually execute the query, it just lets you create a format string and it helps when you're making queries IMO.  Look sprintf() in the manual if you're really curious.  The syntactic part of the query is the SQL-standard way of doing an UPDATE.  I think you should get a new PHP book, because PHP is so unlike how it used to be that anything older than 5 years is considered extremely outdated in my book.

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.