psychohagis Posted January 6, 2007 Share Posted January 6, 2007 Ok I have a page that sends messages, or basically just inserts them into a database. I am using a sql statement in the the exact same way as to which I've used it before and had it work, except this time it is not working. can anyone help?[code]$sql = "INSERT INTO messages SET to='$to', from='$from', subject='$subject', message='$message', received='$received'";if (!@mysql_query($sql)) { echo '<p>Error sending message' . mysql_error() . '</p>';} [/code]But when I run this I get the following error:[quote]Error sending message 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 'to='1', from='1', subject='Hello', message='Hello how are[/quote]it should continue [b]message='hello how are you',received=[/b] and then insert the variable $received which = time() Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted January 6, 2007 Share Posted January 6, 2007 May i have a look at the describe or structure for your messages table?-Andy Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 [table][tr][td][b]Field[/b][/td][td][b]Type[/b][/td][td][b]Default[/b] [/td][td][b]Extra[/b][/td][/tr][tr][td][u]id[/u][/td][td]int(11)[/td][td][/td][td]auto_increment (primary)[/td][/tr][tr][td]to[/td][td]int(11)[/td][td]0[/td][td][/td][/tr][tr][td]from[/td][td]int(11)[/td][td]0[/td][td][/td][/tr][tr][td]subject[/td][td]varchar(50) [/td][td][/td][td][/td][/tr][tr][td]message [/td][td]longtext [/td][td][/td][td][/td][/tr][tr][td]received[/td][td]bigint(20)[/td][td]0[/td][td][/td][/tr][tr][td]read[/td][td]int(11)[/td][td]0[/td][td][/td][/tr][/table] Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted January 6, 2007 Share Posted January 6, 2007 When you use an inset dont use SET you use Values...Replace your code with...INSERT INTO `messages` ( `id` , `to` , `from` , `subject` , `message` , `recieved` , `read` ) VALUES (NULL , '1', '1', '$subject', '$message', '$recieved', NULL); Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 ok thankyouid actually useINSERT INTO `messages` ( `id` , `to` , `from` , `subject` , `message` , `received` , `read` ) VALUES (NULL , '$to', '$from', '$subject', '$message', '$received', NULL);but rather than putting NULL couldnt I just do:[code]INSERT INTO `messages` (`to` , `from` , `subject` , `message` , `received`) VALUES ( '$to', '$from', '$subject', '$message', '$received');[/code] Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted January 6, 2007 Share Posted January 6, 2007 Yeah sure thats fine!Let me know if it works-Andy 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.