PDA

Click to See Complete Forum and Search --> : SQL LIKE clause in PHP


Memnoch1207
Sep 5th, 2002, 04:53 PM
I have a form with a textbox for a name. The user enters the name (or just a couple of letters) and the SQL statement searches the database for any names in the name field that match what the user put into the textbox...problem is the sql statement isn't returning any information...here is what the sql query looks like


$cnx = odbc_connect( 'test' , '', '' );
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE'" . $_REQUEST['Name'] . "'");


any help would be appreciated.

chrisjk
Sep 5th, 2002, 05:32 PM
You're forgeting the wildcards (% or _)

$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%$_REQUEST[Name]%'");

Memnoch1207
Sep 6th, 2002, 02:35 PM
Thanks chrisjk
here is what it had to look like to work...

$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%" . $_REQUEST['Name'] . "%'");

chrisjk
Sep 6th, 2002, 04:53 PM
You shouldn't need to seperate then concatenate, but if it works, what the hell ;)

cpradio
Sep 6th, 2002, 05:53 PM
Originally posted by Memnoch1207
Thanks chrisjk
here is what it had to look like to work...

$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%" . $_REQUEST['Name'] . "%'");

I use this method:
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%{$_REQUEST['Name']}%'");