skipskap Posted April 22, 2007 Share Posted April 22, 2007 Hey all, I'm new to the forums wahey! I have ran into a problem and hopefully someone can let me know how to fix it. Basically, I have a text field and a submit button, once the submit button is clicked I want it to search the database looking for the anything that matches what the user typed into the text field. Here is what I have done so far... <body> <?php if(isset($_POST['search'])) { // connect to database files include 'config.php'; include 'connect.php'; // variables $search=$_POST["search"]; $query = "SELECT name, colour FROM pink LIKE '%$search%'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name :{$row['name']} <br>" . "Message : {$row['colour']} <br><br>"; } // close database include 'close.php'; echo "Search Results"; } else { ?> <form method="post"> <table width="500" border="2" cellspacing="0" cellpadding="0"> <tr> <td colspan="2">Please fill out the form below:</td> </tr> <tr> <td>search:</td> <td> <input name="search" type="text" /> </td> </tr> <tr> <td>Click >></td> <td> <input name="submit" type="submit" id="submit" value="search"> </td> </tr> </table> </form> <?php } ?> </body> Any help with this would be much appreciated! Thanks, Jordan Quote Link to comment https://forums.phpfreaks.com/topic/48153-solved-retrieving-informaton-from-database/ Share on other sites More sharing options...
AndyB Posted April 22, 2007 Share Posted April 22, 2007 You need to specify what field you're searching on: ... FROM pink WHERE somefieldname LIKE '%$search%' Quote Link to comment https://forums.phpfreaks.com/topic/48153-solved-retrieving-informaton-from-database/#findComment-235404 Share on other sites More sharing options...
skipskap Posted April 22, 2007 Author Share Posted April 22, 2007 I just want it to go through all the fields in the database, for both 'form' and 'colour'. I am not sure what to put for this WHERE statement. Could you maybe give me and example, in reference to a database? Thanks for the quick reply! Quote Link to comment https://forums.phpfreaks.com/topic/48153-solved-retrieving-informaton-from-database/#findComment-235408 Share on other sites More sharing options...
skipskap Posted April 22, 2007 Author Share Posted April 22, 2007 Happy days, it worked. Thanks very much for the help mate! Quote Link to comment https://forums.phpfreaks.com/topic/48153-solved-retrieving-informaton-from-database/#findComment-235409 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.