Jump to content

Archived

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

cstegner

stupid insert query wont work, beyond me.

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
YES!! it worked and thank you.

It sucks when you spend like 2 hours on what you expected to take 3-5 min :P

Share this post


Link to post
Share on other sites

×

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.