Results 1 to 5 of 5

Thread: SQL LIKE clause in PHP

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    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

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    You're forgeting the wildcards (% or _)
    PHP Code:
    $cur odbc_exec$cnx"SELECT * FROM test WHERE Name LIKE '%$_REQUEST[Name]%'"); 

  3. #3

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  4. #4
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    You shouldn't need to seperate then concatenate, but if it works, what the hell

  5. #5
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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']}%'"); 
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width