Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.