0

Hi guys,

A problem occured when i tried to run the php file. The error was;

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

Plz guys help me to figure out the problem. I've tried many ways, and it seems none of it worked.This is the query;

$query ="SELECT * FROM $SQL_COUNTTABLE WHERE (SC_REFERENCE LIKE \"$REFERENCE\") AND (SC_NAME LIKE \"$COUNTERNAME\") AND (SC_SINCE = \$DELOLDTIME\)";

Hopefully you guys can help me. Thanks in advanced

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by chaom79
0

You must wrap string literals within single quotes. You also have some extraneous parenthesis in your query. Try this:

$query ="SELECT *"
	." FROM ".$SQL_COUNTTABLE
	." WHERE SC_REFERENCE LIKE '".$REFERENCE."'"
	." AND SC_NAME LIKE '".$COUNTERNAME."'"
	." AND SC_SINCE = '".$DELOLDTIME."'";

This query should execute--assuming those are legitimate column names and the variables contain valid values. However, if you really want to do "LIKE", you normally want to surround the value with percent signs. Percent signs are ANSI SQL wildcards.

$query ="SELECT *"
	." FROM ".$SQL_COUNTTABLE
	." WHERE SC_REFERENCE LIKE '%".$REFERENCE."%'"
	." AND SC_NAME LIKE '%".$COUNTERNAME."%'"
	." AND SC_SINCE = '".$DELOLDTIME."'";
0

Thank you so much Troy. You really helped me solved the problem. Thanks again!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.