Jump to content

syntax error...


m00nz00mer

Recommended Posts

can someone tell me what is wrong with this code...

 

$formQueryComment = "INSERT INTO nbc_bookreview (reviewText) VALUES ('$formComment') WHERE bookISBN='".$_GET['bookID']."'"; mysql_query($formQueryComment) or die(mysql_error());

 

im getting...

 

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 bookISBN='0201708574'' at line 1

 

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

basically this is what im trying to do...

 

//Form Processing

if(isset($_POST['submitted'])) {

 

$formUser = trim($_POST['userName']);

  $formPassword  = trim($_POST['passWord']);

  $formName = trim($_POST['fullName']);

  $formComment = trim($_POST['comments']);

 

$formQuery = "INSERT INTO nbc_user (userID, UserName) VALUES ('$formUser', '$formName')"; mysql_query($formQuery) or die(mysql_error());

$formQueryComment = "INSERT INTO nbc_bookreview (reviewText) VALUES ('$formComment') WHERE bookISBN = '".$_GET['bookID']."'"; mysql_query($formQueryComment) or die(mysql_error());

 

//Refresh the page

echo "<meta http-equiv='refresh' content='1'>";

 

}

 

Link to comment
https://forums.phpfreaks.com/topic/92205-syntax-error/#findComment-472346
Share on other sites

I suspect you don't understand the idea behind INSERTing data in a table. When you INSERT, you create an entirely new row, and WHERE clauses aren't used except when you're working with pre-existing data.

 

If you're trying to create a new row with a book's review, you're probably going to want something along these lines:

 

INSERT INTO nbc_bookreview (reviewText, bookISBN) VALUES ('$formComment', '$bookID');

 

And when you're describing to us what you want to do, you need to describe it in your own words, not just show us your code. Your code may be (in this case, it is) faulty, so we can't tell what it is you're trying to do.

Link to comment
https://forums.phpfreaks.com/topic/92205-syntax-error/#findComment-472352
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.