SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Keyword searching. I'm sure there is a simple answer

    Hi

    I wonder if someone could help me with this very simple question which is annoying me. I have setup a kind of news database and want to keyword search it.

    However my search box is not working properly. My search box uses the code

    Code:
    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=GET>
    Search News: 
    <input type=text name=search_word value="<?PHP echo "$search_word"?>">
    <input type=submit name="Submit_Query" value="Submit">
    </form>
    But using IE 6.0 if I enter a string to search for and then press the return key on the keyboard rather than the Submit button, the search does not work because the In my code I use the following statement

    PHP Code:
    if ("Submit" == $Submit_Query) { 
    For some reason when I press the return key the submit part is not added to the form processing, so the search fail.

    In IE if I use the mouse and press the submit key or in Netspace 6.2 if I press the return key or Submit button it all works fine, but not in IE when I just press return.

    To see what I mean, take a look at
    http://www.infotransport.co.uk/news/test/search.php.

    Any help with solving this problem would be most appreciated.

    Thanks

    Keith

  2. #2
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for that if statement try coding it like so:

    if ($Submit_Query == 'Submit') {
    }

    instead of the way you had it. this might fix it, i'm not sure.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  3. #3
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it did not work.

    The problem is the URL which is generated.

    If enter the word "london" and press the return key in IE 6, the URL appears as search.php?search_word=london.

    When Submit is clicked on with the mouse, everything works fine. The URL is now search.php?search_word=london&Submit_Query=Submit.

    Because the Submit_Query bit is missing from the form processing, the form is not being handled properly.

    Any more suggestions would be most welcome.

  4. #4
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use POST for one thing (cooler that way ).

    Plus, don't bother checking for $submitQuery, simply say
    if( $search_word ) {
    ..
    }

    since the only time search_word will be non-empty is if they type something in and hit submit.

    Or, if you don't like that, define a hidden value:
    <input type='hidden' name='something' value='true'>

  5. #5
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that. The IF search_word idea worked great.

    Thanks.


Bookmarks

Posting Permissions

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