Hello
Here i will show how to make a simple searchengine. First we must make a form:
search.html
HTML Code:
<form action="search.php" method="post">
<input type="text" name="find" size="30" /><br />
<input type="submit" value="Search" />
</form>
Now we must make this php part.
search.php
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 [b]$item[/b] variable
$item = $_REQUEST['find'];
// This will take all info from database where row [i]tutorial[/i] is $item and collects it into [b]$data[/b] 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>";
}
?>
__________________
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
| Need help? Send a
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.