Page 1 of 1
Gah! Whats wrong with this simple Query?
Posted: Wed Dec 31, 2008 12:05 pm
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.
Re: Gah! Whats wrong with this simple Query?
Posted: Wed Dec 31, 2008 12:10 pm
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
Re: Gah! Whats wrong with this simple Query?
Posted: Wed Dec 31, 2008 12:24 pm
by Mark Baker
Why do you use separate day month and year fields on the database rather than a simple date datatype field