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

Recommended Answers

All 2 Replies

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."'";

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.