Gah! Whats wrong with this simple Query?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Gah! Whats wrong with this simple Query?

Post by oscardog »

it's bugging me, it just wont insert...

Code: Select all

mysql_query("INSERT INTO diaryentries (userid, day, month, year, event) VALUES ('".$user_id."', '".$day."', '".$month."' , '".$year."'. '".$diaryentry."')");
Any help?

Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Gah! Whats wrong with this simple Query?

Post by John Cartwright »

Add error reporting, and better yet, escape your values properly.

Code: Select all

$sql = " 
   INSERT INTO diaryentries 
   (
      userid, 
      day, 
      month, 
      year, 
      event
   )
   VALUES 
   (
      '". mysql_real_escape_string($user_id) ."', 
      '". mysql_real_escape_string($day). "', 
      '". mysql_real_escape_string($month) ."',
      '". mysql_real_escape_string($year) ."',
      '". mysql_real_escape_string($diaryentry)."'
   )
";
 
mysql_query($sql) or die(mysql_error());
I've fixed it in my example, but you had a period in place of a comma
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Gah! Whats wrong with this simple Query?

Post by Mark Baker »

Why do you use separate day month and year fields on the database rather than a simple date datatype field
Post Reply