I would like to make some query using the SELECT function. However i wasnt able to get the results i want.
My code is as follow:

$sql = "SELECT *
FROM device 
WHERE ((device_num like '%$val_d%') OR (dib like '%$val_dp%')) ";

can i write it in this way? pls advise thanks people..:)

Try replacing it with the following:

$sql = 'SELECT * FROM device WHERE `device_num` LIKE "'.mysql_real_escape_string($val_d).'" OR `dib` LIKE "'.mysql_real_escape_string($val_dp).'"';

Hi..
where should i place the wildcard?

If you want wildcards then the following contains the wildcards:

$sql = 'SELECT * FROM device WHERE `device_num` LIKE "%'.mysql_real_escape_string($val_d).'%" OR `dib` LIKE "%'.mysql_real_escape_string($val_dp).'%"';

I would like to make some query using the SELECT function. However i wasnt able to get the results i want.
My code is as follow:

$sql = "SELECT *
FROM device 
WHERE ((device_num like '%$val_d%') OR (dib like '%$val_dp%')) ";

can i write it in this way? pls advise thanks people..:)

in first place check whether $val_d and $val_dp variables are set when this query is formed, otherwise your query may get executed like -

$sql = "SELECT * FROM device WHERE ((device_num like '') OR (dib like '')) ";
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.