user3355035 user3355035 - 3 months ago 4
PHP Question

mysql query error n error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

when I run following query i get the error


error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near


$query_rsDept = "SELECT * FROM result-ba where rollno =".$_REQUEST['Roll_No']." order by SUBORD";


why?

Answer

You have a dash in your table name which is not allowed unless you use a delimited identifier. This mean you will need to wrap it in ticks:

 SELECT * FROM `result-ba` 

FYI, you are wide open to SQL injections.