|
-
Sep 5th, 2002, 04:53 PM
#1
Thread Starter
Frenzied Member
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.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Sep 5th, 2002, 05:32 PM
#2
PowerPoster
You're forgeting the wildcards (% or _)
PHP Code:
$cur = odbc_exec( $cnx, "SELECT * FROM test WHERE Name LIKE '%$_REQUEST[Name]%'");
-
Sep 6th, 2002, 02:35 PM
#3
Thread Starter
Frenzied Member
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'] . "%'");
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Sep 6th, 2002, 04:53 PM
#4
PowerPoster
You shouldn't need to seperate then concatenate, but if it works, what the hell
-
Sep 6th, 2002, 05:53 PM
#5
Fanatic Member
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']}%'");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|