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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/ 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? ??? Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379580 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379582 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? Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379584 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379585 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? Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379586 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 Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379588 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379591 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379593 Share on other sites More sharing options...
SJames Posted October 28, 2007 Author Share Posted October 28, 2007 same error as before Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379595 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 Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379596 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') Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379599 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 Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379601 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379602 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); ??? Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379604 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379606 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379607 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. Link to comment https://forums.phpfreaks.com/topic/75057-solved-what-is-wrong-with-this/#findComment-379608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.