0

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"

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by futhonguy
0

try this:

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

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) . "
0

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.:)

This question has already been answered. 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.