Hi,

I stuck on this query for quite a while. will appreciate if someone can help me to look at this query and correct me where i had done wrongly.

$val_d = $_GET['val_d'];
 
$sql = "SELECT *
            FROM device";
		
$sql .="WHERE device_num LIKE '%$val_d%' ";

the error message prompted 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 'LIKE '%" . urlencode($val_d) . "%'' at line 2"

try this:

$val_d = $_GET['val_d'];
 
$sql = "SELECT *
            FROM device";
		
$sql .="WHERE device_num LIKE ". $val_d;

try this:

$val_d = $_GET['val_d'];
 
$sql = "SELECT *
            FROM device";
		
$sql .="WHERE device_num LIKE ". $val_d;

Hi JRM,

I tried to use your method, the value of $val_d was not passed to this script from another php file.
when i did a echo earlier on the script before the query, $val_d was passed over. Upon getting into the query, it somehow didnt get thru and error produced as

SELECT *	
FROM device  
WHERE device_num LIKE" . urlencode($val_d) . "

Hey, i managed to figure out my problem. Error was found on the php file that supposed to pass the variable over to this script.

Thanks for the help and sorry for the trouble.:)

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.