We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,063 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Syntax error when comparing date

Hello, i'm having some problem when comparing date (from user input) with the date inside database. The format of both dates are the same (YYYY-MM-DD). This is the error it shows

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 date = 2012-08-30' at line 1

and the code

mysql_query("INSERT INTO $attlist ($tempName) VALUES ($tempValue) WHERE date = '$date' ") or die(mysql_error());

Really appreciate your help. Thanks

3
Contributors
3
Replies
1 Hour
Discussion Span
8 Months Ago
Last Updated
4
Views
scholarwithfire
Newbie Poster
9 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

date is reserved word you shouldn't use it as a field name
you can still get around this by wrapping date in backticks

`date`='$date'
jstfsklh211
Junior Poster
100 posts since Apr 2011
Reputation Points: 34
Solved Threads: 27
Skill Endorsements: 1

Changed to

`date` = '$selected_date'

still getting the same syntax error.

Thanks for the reply though

scholarwithfire
Newbie Poster
9 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

You sure you used backticks and not single quotes? Sorry, just asking.

diafol
Keep Smiling
Moderator
10,655 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0625 seconds using 2.73MB