Hello
Here i will show how to make a simple searchengine. First we must make a form:
search.html
Now we must make this php part.Code:<form action="search.php" method="post"> <input type="text" name="find" size="30" /><br /> <input type="submit" value="Search" /> </form>
search.php
Code:<?php // First connect to database $host = "localhost"; $dbuser = "username"; $dbpass = "password"; $db = "database"; $con = mysql_connect($host, $dbuser, $dbpass); if(!$con){ die(mysql_error()); } $select = mysql_select_db($db, $con); if(!$select){ die(mysql_error()); } // Now collect all info into $item variable $item = $_REQUEST['find']; // This will take all info from database where row tutorial is $item and collects it into $data variable $data = mysql_query("SELECT * FROM tutorials WHERE tutorial LIKE '%$item%'"); // This creates a loop which will repeat itself until there are no more rows to select from the database. We getting the field names and storing them in the $row variable. This makes it easier to echo each field. while($row = mysql_fetch_array($data)){ echo $row['date']. "<br>"; echo $row['id']. "<br>"; } ?>
Bookmarks