SJames Posted October 28, 2007 Share Posted October 28, 2007 $sql = "INSERT INTO messages (sender, reciever, date, read, subject, message) VALUE ('$sender', '$reciever', '$date', 'no', '$subject', '$message')"; mysql_query($sql); It responds that there's a syntax error. When I print $sql it comes out correctly. Quote Link to comment Share on other sites More sharing options...
yaytome Posted October 28, 2007 Share Posted October 28, 2007 I don't that much, but shouldn't it be VALUES instead of VALUE? ??? Quote Link to comment Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 For some reason, now when I use VALUES, the entire page gets completely messed up... Edit: It's because I had an or die () set that the page was getting messed up. But this means that there is an error somewhere in there. Quote Link to comment Share on other sites More sharing options...
peranha Posted October 28, 2007 Share Posted October 28, 2007 Are you getting any error messages, or anything on the screen? Quote Link to comment Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 Nothing shows up on screen, but nothing gets added to the database, and if an or die() is set, the whole page gets messed up. Quote Link to comment Share on other sites More sharing options...
peranha Posted October 28, 2007 Share Posted October 28, 2007 How about you apache log file, is there any errors in it? Quote Link to comment Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 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 'read, subject, message) VALUES ('test1', 'test2', '1193537533', 'no', 'test', 'test')' at line 1 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 try this one <?php $q = "Insert into `messages` (sender, reciever, date, read, subject, message) Values('".$sender."', '".$reciever."', '".$date."', 'no', '".$subject."', '".$message."')"; mysql_query($q) or die(mysql_error()."<br />".$q; ?> And if it errors paste the exact error in. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 also just a note it doesn't save you much, but if you make the read field default to no you can cut down the query. Quote Link to comment Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 same error as before Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 please paste it as I need to see it using this specific query I gave you or I can't help u Quote Link to comment Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 Like I said, same error as before: 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 'read, subject, message) Values('test1', 'test2', '1193537533', 'no', 'test', 'test')' at line 1 Insert into `messages` (sender, reciever, date, read, subject, message) Values('test1', 'test2', ''1193537533, 'no', 'test', 'test') Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 well you obviously did not use what I said <?php<?php $q = "Insert into `messages` (sender, reciever, date, read, subject, message) Values('".$sender."', '".$reciever."', '".$date."', 'no', '".$subject."', '".$message."')"; mysql_query($q) or die(mysql_error()."<br />".$q); ?> as it would echo out the sql error a break line and the query Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 and I think inevertinently I have found your problem. Certain words are "special" in mysql like id, you must quote them. I believe read is one of these, so try what I gave you see if it errors, if it does quote out the field names and see what happens. Quote Link to comment Share on other sites More sharing options...
yaytome Posted October 28, 2007 Share Posted October 28, 2007 what will happen if you put it like this $sql = "INSERT INTO messages (`sender`, `reciever`, `date`, `read`, `subject`, `message`) VALUE ('$sender', '$reciever', '$date', 'no', '$subject', '$message')"; mysql_query($sql); ??? Quote Link to comment Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 Okay, I took out the whole read part since it's not important whether it's set to no for the pages that use it. Anyway this fixed the problem. Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 read is not but date is. Also, you need a space after VALUES. Try... <?php $sql = "INSERT INTO messages ( sender, reciever, `date`, read, subject, message ) VALUES ( '$sender', '$reciever', '$date', 'no', '$subject', '$message' );"; if (mysql_query($sql)) { echo "success"; } else { echo mysql_error() . "<br />$sql"; } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 yeah like I said set it to default to no also if its a yes/no sort of field the bool type is more approreate as it takes up less space. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.