m00nz00mer Posted February 21, 2008 Share Posted February 21, 2008 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 More sharing options...
p2grace Posted February 21, 2008 Share Posted February 21, 2008 You don't use WHERE statements in INSERT queries. Are you trying to run an update query? Link to comment https://forums.phpfreaks.com/topic/92205-syntax-error/#findComment-472344 Share on other sites More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 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 More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 and both userID and bookISBN are PKs Link to comment https://forums.phpfreaks.com/topic/92205-syntax-error/#findComment-472347 Share on other sites More sharing options...
neylitalo Posted February 21, 2008 Share Posted February 21, 2008 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 More sharing options...
m00nz00mer Posted February 21, 2008 Author Share Posted February 21, 2008 thank you, thats sorted things out in my head! Link to comment https://forums.phpfreaks.com/topic/92205-syntax-error/#findComment-472551 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.