SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Basic search script problem

    Can anyone tell me what is wrong with this code?
    PHP Code:
    <?php

    if (("$tablename== "Select:")) {

    print 
    "Please select a category to search in before you can proceed with your query.";

    } elseif ((
    "$tablename== "$tablename")) {

    $Host "localhost";
    $User "";
    $Password "";
    $DBName "";
    $Link mysql_connect ($Host$User$Password);

    $Query "SELECT * FROM $tablename WHERE LOWER(name) LIKE LOWER('%$keyword%') OR LOWER(products) LIKE LOWER('%$keyword%') ORDER BY id DESC";
    $Result mysql_db_query ($DBName$Query$Link);

    // Fetch the results from the database.

    while($Row mysql_fetch_array($Result)) 
      {
    echo 
    "Search results for: <u>$keyword</u> in $tablename<br />";
    echo 
    "<ol>";

    echo 
    "<li>$Row[name]<br /><b>Country:</b>$Row[country]<br /><b>Products:</b>$Row[products]<br /><br />";
        
    echo 
    "</ol><br />";

    mysql_close ($Link);

    } else {

    echo 
    "<b>No Records Found for:</b> <u>$keyword</u> in $tablename<br /><br /><b>Try some of the following:<br /><br />- Make sure the keyword is spelled correctly.<br />- Try a different keyword.<br />- Try a more general keyword.</b><br /><br />";

    }

    ?>

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Details. What's it supposed to do? What's it doing? Error messages? I am not a PHP parser. Give me details.
    Aaron Brazell
    Technosailor



  3. #3
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is there something wrong with it? Or is this just a question out of the blue?
    Mike
    It's not who I am underneath, but what I do that defines me.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Geez...I'm sorry...

    It's telling there is an unexpected $ on line 119, and the only thing on that line is </HTML>.

  5. #5
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "</HTML>" doesn't appear in the code fragment you posted.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  6. #6
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    his is because you must have forgot to close a bracket } somehwere.

    if your while loop should appear in your elseif block, put a bracket at the end of the code you posted above, it should fix it.

    asT.

  7. #7
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by astericks
    his is because you must have forgot to close a bracket } somehwere.

    if your while loop should appear in your elseif block, put a bracket at the end of the code you posted above, it should fix it.

    asT.
    Okay that fixed the script, but now when the search term returns no results I get an error, how do I check if the search returned no results?

    This is the error I get when there are no results to display:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/foodsfo/public_html/shared/search2.php on line 80
    And line 80:
    while($Row = mysql_fetch_array($Result))

  8. #8
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That means the query failed.
    Mike
    It's not who I am underneath, but what I do that defines me.


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
  •