Jump to content

stupid insert query wont work, beyond me.


cstegner

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.