cstegner Posted May 7, 2006 Share Posted May 7, 2006 A super simple insert query that I have used at least 2 million times, wont work. let me know if you can see why.[code]if(isset($_POST['send_message'])){ $q_send_message = mysql_query("INSERT INTO messages (to, from, subject, message, date) values ('$id', '$user_id', '$subject', '$message', '$today')"); echo " <div id=\"middle\"> <br /><br /> <div class=\"body_header\">Send Message</div> <p class=\"body_text\" /> <b>Your message has been sent!</b><br /><br /> Return to <a href=\"/userpage/index.php\">User Page</a>. </div> "; include($_SERVER['DOCUMENT_ROOT'].'/inc/home_bottom.php'); exit();}[/code]the table name is definitley messages. I also tried setting all the values directly in the query rather then variables, to see if they were the problem. It would still not work. I have also tested all the variables they all work. Every thing in the if runs correctly other then the insert query.thanks for the help. Link to comment https://forums.phpfreaks.com/topic/9221-stupid-insert-query-wont-work-beyond-me/ Share on other sites More sharing options...
AndyB Posted May 7, 2006 Share Posted May 7, 2006 Just a thought. "FROM" and "TO" are MySQL reserved words and shouldn't be used as a column name. Backticks might save you:[code]"INSERT INTO messages (`to`, `from`, subject, message, date) values ('$id', '$user_id', '$subject', '$message', '$today')"[/code]It that doesn't do it, add a sensible mysql error message to the query to see if an sql error exists. Link to comment https://forums.phpfreaks.com/topic/9221-stupid-insert-query-wont-work-beyond-me/#findComment-33966 Share on other sites More sharing options...
.josh Posted May 7, 2006 Share Posted May 7, 2006 even if that's not the problem, it's still a problem. you can't use reserved words as column names. for some silly reason it will actually let you name a column a reserved word, but from then on, you can't do anything with it. Link to comment https://forums.phpfreaks.com/topic/9221-stupid-insert-query-wont-work-beyond-me/#findComment-33973 Share on other sites More sharing options...
cstegner Posted May 7, 2006 Author Share Posted May 7, 2006 YES!! it worked and thank you.It sucks when you spend like 2 hours on what you expected to take 3-5 min :P Link to comment https://forums.phpfreaks.com/topic/9221-stupid-insert-query-wont-work-beyond-me/#findComment-34016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.