-
SQL LIKE clause in PHP
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
Code:
$cnx = odbc_connect( 'test' , '', '' );
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE'" . $_REQUEST['Name'] . "'");
any help would be appreciated.
-
You're forgeting the wildcards (% or _)
PHP Code:
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%$_REQUEST[Name]%'");
-
Thanks chrisjk
here is what it had to look like to work...
PHP Code:
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%" . $_REQUEST['Name'] . "%'");
-
You shouldn't need to seperate then concatenate, but if it works, what the hell ;)
-
Quote:
Originally posted by Memnoch1207
Thanks chrisjk
here is what it had to look like to work...
PHP Code:
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%" . $_REQUEST['Name'] . "%'");
I use this method:
PHP Code:
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%{$_REQUEST['Name']}%'");