Jump to content

search box.. SEARCH IN THE DATABASE


postbil.com

Recommended Posts

 

Hi people

 

I have a little problem with my SQL statement. I am working on a script that makes it posibel the user to search for their friends and add them as contacts. In my database I HAVE fields for first name, last name and e-mail. I have created a field, and the button in my html code, I want to allow users to search by first name, last name and e-mail from the same search box. How can I make it?

 

Postbil.com

 

<?php
// Include the connection to the database
    include ('../DB/db.connect.inc.php');  

// Create the variabels for the text field
    $find_contact = (isset($_POST['find_contact'])) ? trim($_POST['find_contact']) : '';  

// if there are press "Søg" 
    if(isset($_POST['Søg'])) {
        $query = 'SELECT * 
                FROM 
                     site_user 
                WHERE
                    * 
                LIKE
                    " .. " ';
                  
    $result = mysql_query($query, $conn) or die (mysql_error());
             
    } 
?>
<html>
    <head>
    
    </head>
    <body>
        <form method="post">
            <fieldset>
                <legend>Søg efter kontaktpersoner</legend>
                    <center>
                        <table>
                            <tr>
                                <td><input type="text" name="find_contact" id="find_contact"></td>
                                <td><input type="submit" name="submit" value="Søg"></td>
                            </tr>
                        </table>
                    </center>
                </fieldset>
<?php
// create loop with the result
    while ($row = mysql_fetch_assoc($result)) {
        extract($row);
            echo '<fieldset>';
            echo '<legend>';
            echo $firstName;
            echo ' ';
            echo $lastName;
            echo '</legend>';
                echo '<table>';
                    echo '<tr>';
                        echo '<td>Fornavn</td>';
                        echo '<td>' . $firstName . '</td>';
                    echo '</tr>';
                    echo '<tr>';
                        echo '<td>Efternavn</td>';
                        echo '<td>' . $lastName . '</td>';
                    echo '</tr>';
                echo '</table>';
            echo '</table>';
    }
?>
                
        </form>
    </body>
</html>    
              

Link to comment
https://forums.phpfreaks.com/topic/187135-search-box-search-in-the-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.