0

I have face a syntax error 1064.

I wanted to download a specific data, depending on the date that the user key in, from the database but i got this error:

Couldn't execute query: 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 '?' at line 1 1064

This is my codes:

$ddate = $_GET['Absent_Date'];
$sql = ("Select * from $DB_TBLName WHERE `Absent_Date` = $ddate");

Please help me. Thanks:}

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • 1
    The site visitor didn't know he was supposed to surround `?` in single quotes. If you allow the site visitor to freely compose SQL code, you can't avoid getting invalid SQL now and then. – Álvaro González Aug 29 '13 at 07:34
  • You need to validate the user input before you accept it and use it as a database value. As well you have a couple of syntax problems: 1. No need for parentheses (I don't know if it's bad or just unneccessary) 2. Move the quotes from the field name to the value: `Absent_Date = '$ddate'` – ygesher Aug 29 '13 at 07:47

0 Answers0