SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Hanabi's Avatar
    Join Date
    Mar 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Search form problems (no output)

    Hi,
    I try to write a program that will perform a search according to the criteria selected by the user.
    On the search I've got the following variables:
    $s_lastname
    $s_firstname
    $s_email
    ...(20 variables in totals)

    Even if the people i'm looking exist in the database the search always returns zero. Can anyone tell me why it goes wrong?

    PHP Code:
    <?
    // connect to database
    mysql_connect ("localhost", "username", "password");

    // Check to select a criteria

    $sql = 'SELECT lastname, firstname, email FROM tablename WHERE 1';

    // Personal Details
    if ($s_lastname != 'None') $sql .= " AND last_name = '$s_lastname'";
    if ($s_firstname != 'None') $sql .= " AND firstname = '$s_firstname'";
    if ($s_email != 'None') $sql .= " AND email= '$s_email";
    ...

    $result = mysql_db_query (stelladb, $sql); 

    // If the query doesn't return any result
    echo "Your search has identified " .mysql_num_rows($result). " people(s)"; 

    // Display the results in a table
    echo "<br>";
    echo "<table>";
    while ($row = mysql_fetch_row($result)) {
        $field = mysql_num_fields($result);
        echo "<tr>";
        
        for( $i=0; $i<$field; $i++) {
            echo "<td>" . $row[$i] . "</td>";
            
    }
        echo "</tr>";
    }
    echo "</table>";
    ?>
    Thanks for your time.

    Hanabi.

  2. #2
    Shiver me timbers!! anthony_irl's Avatar
    Join Date
    Aug 1999
    Location
    Dublin, Ireland
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's this line:

    PHP Code:
    $result mysql_db_query (stelladb$sql); 
    Should it be this?:
    PHP Code:
    $result mysql_db_query ('stelladb'$sql); 
    Anthony - How's tings?

    24 hours in a day, 24 beers in a case. Coincidence? I think not.
    Contact me by: PM Email NEW! Carrier Pigeon

  3. #3
    SitePoint Enthusiast Hanabi's Avatar
    Join Date
    Mar 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    No, it doesn't work either
    Thanks for your time.

    Hanabi.

  4. #4
    Shiver me timbers!! anthony_irl's Avatar
    Join Date
    Aug 1999
    Location
    Dublin, Ireland
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm. Whats the name of the database and tables you are trying to access?
    Anthony - How's tings?

    24 hours in a day, 24 beers in a case. Coincidence? I think not.
    Contact me by: PM Email NEW! Carrier Pigeon

  5. #5
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You haven't declared the databasde you are using.

    PHP Code:
    mysql_select_db(database); 
    Wanna be php coder!


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
  •