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() Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/ 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 Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154193 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] Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154198 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); Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154199 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] Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154203 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Author Share Posted January 6, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154206 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 Link to comment https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.