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
https://forums.phpfreaks.com/topic/162663-solved-whats-wrong-with-my-query/
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. 

 

|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

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 . "');

 

 

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.