timlondon Posted December 18, 2006 Share Posted December 18, 2006 I'm having a problem using PHP to insert a date into a MySQL field.The field is already defined as a date data type.The offending PHP code is:$sql = "INSERT INTO user (maindob) values ('$newdata[1]') WHERE account = '$newdata[0]'";echo $sql;$sql therefore equals:INSERT INTO user (maindob) values (1966-08-26) WHERE account = 'alpha01'But I'm getting the following error: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 'WHERE account = 'alpha01'' at line 1Any advice would be much appreciated. Link to comment https://forums.phpfreaks.com/topic/31105-phpmysql-date-syntax-problems/ Share on other sites More sharing options...
obsidian Posted December 18, 2006 Share Posted December 18, 2006 Because you don't have your date within quotes, MySQL is attempting to run an arithmetic operation on your date (1966 minus 08 minus 26). You need to simply place single quotes around the date, and you should be fine:[code]<?php$sql = "INSERT INTO user (maindob) VALUES ('$newdata[1]')";?>[/code]Good luck Link to comment https://forums.phpfreaks.com/topic/31105-phpmysql-date-syntax-problems/#findComment-143615 Share on other sites More sharing options...
kenrbnsn Posted December 18, 2006 Share Posted December 18, 2006 The "where" clause is not legal on an insert.Ken Link to comment https://forums.phpfreaks.com/topic/31105-phpmysql-date-syntax-problems/#findComment-143619 Share on other sites More sharing options...
obsidian Posted December 18, 2006 Share Posted December 18, 2006 [quote author=kenrbnsn link=topic=119113.msg487339#msg487339 date=1166454509]The "where" clause is not legal on an insert.Ken[/quote]Haha! Wow... thanks, Ken. Can't believe I actually just posted that :P I completely missed it! Link to comment https://forums.phpfreaks.com/topic/31105-phpmysql-date-syntax-problems/#findComment-143625 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 LOL Even the best here occasionally overlook the little things. You guys are the best!!! Link to comment https://forums.phpfreaks.com/topic/31105-phpmysql-date-syntax-problems/#findComment-143628 Share on other sites More sharing options...
timlondon Posted December 18, 2006 Author Share Posted December 18, 2006 Thanks guys. Changed it to update. Link to comment https://forums.phpfreaks.com/topic/31105-phpmysql-date-syntax-problems/#findComment-143630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.