postbil.com Posted January 4, 2010 Share Posted January 4, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/187135-search-box-search-in-the-database/ Share on other sites More sharing options...
fenway Posted January 6, 2010 Share Posted January 6, 2010 Use code tags next time. All you need to use is check each of the 3 fields, combined with ORs, if the user has provided any input. Quote Link to comment https://forums.phpfreaks.com/topic/187135-search-box-search-in-the-database/#findComment-989555 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.