Jump to content


Photo

stupid insert query wont work, beyond me.


  • Please log in to reply
3 replies to this topic

#1 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 07 May 2006 - 04:49 AM

A super simple insert query that I have used at least 2 million times, wont work. let me know if you can see why.

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();
}

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.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 May 2006 - 05:03 AM

Just a thought. "FROM" and "TO" are MySQL reserved words and shouldn't be used as a column name. Backticks might save you:
"INSERT INTO messages (`to`, `from`, subject, message, date) values ('$id', '$user_id', '$subject', '$message', '$today')"

It that doesn't do it, add a sensible mysql error message to the query to see if an sql error exists.
Legend has it that reading the manual never killed anyone.
My site

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 May 2006 - 06:28 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 07 May 2006 - 01:54 PM

YES!! it worked and thank you.

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users