jamesxg1 Posted April 19, 2009 Share Posted April 19, 2009 if (isset($_POST['Update'])) { $whoto = mysql_real_escape_string(stripslashes($_POST['whoto'])); $date = mysql_real_escape_string(stripslashes($_POST['fromdate'])); $date = date('Y-m-d',strtotime("$date")); $sql = sprintf("UPDATE `unlock` SET whoto = '$whoto', when = '$date'") or die(mysql_error()); $query = mysql_query($sql) or die(mysql_error()); print 'Image Sucessfully Updated.'; } You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when = '2009-04-19'' at line 1 Link to comment https://forums.phpfreaks.com/topic/154751-solved-mysql-error-im-tottally-baffeled-here-s/ Share on other sites More sharing options...
kenrbnsn Posted April 19, 2009 Share Posted April 19, 2009 It's not 'when' it's 'where' Ken Link to comment https://forums.phpfreaks.com/topic/154751-solved-mysql-error-im-tottally-baffeled-here-s/#findComment-813792 Share on other sites More sharing options...
mrMarcus Posted April 19, 2009 Share Posted April 19, 2009 you're using sprintf() incorrectly. if (isset($_POST['Update'])) { $whoto = mysql_real_escape_string(stripslashes($_POST['whoto'])); $date = mysql_real_escape_string(stripslashes($_POST['fromdate'])); $date = date('Y-m-d',strtotime($date)); $sql = sprintf("UPDATE `unlock` SET whoto='%s', when='%s'", $whoto, $date); $query = mysql_query($sql) or die(mysql_error()); print 'Image Sucessfully Updated.'; } else { echo "Update button not pushed / set."; } Link to comment https://forums.phpfreaks.com/topic/154751-solved-mysql-error-im-tottally-baffeled-here-s/#findComment-813797 Share on other sites More sharing options...
soak Posted April 19, 2009 Share Posted April 19, 2009 when is a reserved word (http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html) so you need to enclose it in special quotes (sorry, I don't know the name of them but they're at the top left of my keyboard. Like: `when` = '$date'" Link to comment https://forums.phpfreaks.com/topic/154751-solved-mysql-error-im-tottally-baffeled-here-s/#findComment-813800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.