Jump to content

[SOLVED] Whats wrong with my query?


mike12255

Recommended Posts

I can never fix these/get them right....

 

What is wrong with this one:

 

$sql = "INSERT INTO pages (info) VALUES ('$info') WHERE page = '".$page."' ";

 

it outputs this:

 

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 page = 'wine'' at line 1

 

i though i had it so that one " didnt actually cant as apart of the query

Link to comment
Share on other sites

Did you escape the strings ($info and $page) before you put them in the $sql statement?

 

Add

echo '|' . $sql . '|';

just before you execute the query.  The vertical bars will help isolate the actual query string.  Post what is there and we'll get a better idea of the problem.  There may be something in one of the variables ($info or $page) that the server is interpreting. 

 

Link to comment
Share on other sites

|INSERT INTO pages (info) VALUES ('

 

testdfasddfasdfsfadsfg

') WHERE page = '{wine}' |

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 page = '{wine}'' at line 1

 

I added a <br> after the last | in your code

Link to comment
Share on other sites

Sorry, what am I thinking?  INSERT does not allow a WHERE clause.  The record will be ADDED to the database.

 

Are you trying to UPDATE an existing row?

$sql = "UPDATE pages SET info = '" . $info . "' WHERE page = '".$page."' ";

 

or are you trying to INSERT a new row?

$sql = "INSERT INTO pages (info, page) VALUES ('" . $info . "', '" . $page . "');

 

 

Link to comment
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.