Thursday, 22 August 2013

How to Make a Simple Search Engine using PHP and MySQLi

This post i make on own small search engine using php and mysqli. this search engine search to database user information check on find related content to display the other page. its a basic tips to make a search engine concept also having script download. 

search-engine-img

View code         Download

Database

Database connect to mysqli query  create below format table. the fields to store on user given information.

CREATE TABLE `search`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`desp` varchar(50) NOT NULL,
)


Files


create above file and copy the below file code 

index.php

This page include on search-engine.php file to display on search box its store the client side information using on session to post add-new.php page. 
<html>
<head>
<title>mostlikers</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="mostlikers-top">
<a href="http://karthickinfotech.blogspot.in/">
<img name="mostlikers" style="border:none;"
src="demo.png" title="mostlikers" alt="mostlikers" /></a>
</div>
<div class="login">
<?php include("search-engine.php"); ?>
</div>
<div class="mostlikers-bottom">
<h3><a href="karthickinfotech.blogspot.in/p/chat.html">Click more mostlikers Demos</a></h3></div>
</body>
</html>


add-new.php

This page display on post value to check database and fetch the related statement using as if else statement code 
<?php
$db = new mysqli('localhost', 'root', '', 'test');// change the database connections
?>
<?php
if(isset($_POST['ADD'])!="")
{
$title=$_POST['title'];
$description=$_POST['desc'];
$insert=$db->query("INSERT INTO `search`(title,desp) values('$title','$description')");
if($insert)
{
echo "<script> alert('search the title now') </script>";
}
else
{
echo "<script> alert('unable insert to your details') </script>";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mostlikers</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="mostlikers-top">
<a href="http://karthickinfotech.blogspot.in/">
<img name="mostlikers" style="border:none;" src="demo.png" title="mostlikers" alt="mostlikers" /></a>
</div>
<div class="login">
<?php include("search-engine.php"); ?>
<?php if(($_SESSION['title']!=""))
{
$data=$_SESSION['title'];
$view=$db->query("select * from search where title='$data'");
$check=mysqli_num_rows($view);
if($check!="")
{
while($descri=mysqli_fetch_object($view))
{
?>
<div class="comment_box">
<div style="float:left;"><img src="user.png" width="80" height="80" /></div>
<div>
<?php echo $descri->title; ?>
<hr />
"<?php echo $descri->desp; ?>"
</div>
</div>
<div class="clear"></div>
<?php } }
else
{
?>
<div class="comment_box">
<h1>Search Data Not found</h1>
</div>
<?php
}}
?>
<!--client side add information-->
<div class="addnew">
<form name="add" method="post">
<h2>Add New Record</h2>
<p><label>Title</label><br />
<input type="text" size="40" name="title" title="title" /></p>
<p><label>Descriptions</label><br />
<textarea name="desc" rows="5" cols="30"></textarea></p>
<input type="submit" name="ADD" class="submit" value="ADD" title="ADD" />
</form>
</div>
</div>
</div> <div class="mostlikers-bottom">
<h3><a href="karthickinfotech.blogspot.in/p/chat.html">Click more mostlikers Demos</a></h3></div>
</body>
</html>


search-engin.php

This page as display client side titles in datalist mode. value store and post on session.
<?php
session_start();
if(isset($_POST['submit']))
{
$search=$_POST['search'];
$_SESSION['title']= $search;
if(($_SESSION['title'])!="")
{
header("location:add-view.php");

}
else
{
echo "<script> alert('search box as been empty') </script>";
}
}
?>
<form method="post" class="form-wrapper" method="post">
<h1>Mostlikers Search Engin</h1>
<p><strong>Search your Details ex:Mostlikers</strong></p>
<p>
<input name="search" type="search" list="searchkey" />
<datalist id="searchkey">
<?php
$db = new mysqli('localhost', 'root', '', 'test');// change db connection
$tile=$db->query("SELECT * FROM `search`");
while($storetitle=mysqli_fetch_object($tile))
{
?>
<option value="<?php echo $storetitle->title ?>">
<?php } ?>
</datalist>
<input type="submit" name="submit" class="submit" value="search" />
</p>
</form>



style.css

@charset "utf-8";
body{ margin:0; padding:0;}
.login { width:900px; height:900px; margin:0 auto; -moz-box-shadow:0px 0px 1px 1px #999; -webkit-box-shadow:0px 0px 1px 1px #999; }
.login form { width:600px; height:0 auto; margin:0 auto; }
.mostlikers-top { height:100px; background-color:#f2f2f2; }
.mostlikers-bottom { height:50px; background-color:#f2f2f2; }
input[type=search]
{
border: 1px solid #ccc;
border-radius: 3px;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
width:350px;
min-height: 28px;
padding: 4px 20px 4px 8px;
font-size: 18px;
-moz-transition: all .2s linear;
-webkit-transition: all .2s linear;
transition: all .2s linear;
}
input[type=search]:focus
{
width: 400px;
border-color: #51a7e8;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1),0 0 5px rgba(81,167,232,0.5);
outline: none;
}
.submit{
padding: 6px 20px;
color: #FFF;
border-radius:3px solid #00F;
border:1px solid #CCC;
background: #0099FF;
margin-bottom:4%;
cursor:pointer;
-moz-border-radius: 3px ;
-webkit-border-radius: 3px;
border-radius: 3px ;
}
.comment_box
{
margin:0 auto;
box-shadow: inset 0 1px 15px rgba(0,0,0,0.1);
width:600px; height:100px;
}
.addnew
{
width:500px;
height:100px;
margin:0 auto;
}
.clear
{
padding-top:20px;
}
/* CSS Document */

7 comments:

  1. Let me see that this works or not!
    It will be Live at: atdsearch.tk

    ReplyDelete
  2. Glad to read your post...Thanks for sharing such a nice information, its beneficial for me. I have you bookmarked to check out new stuff you post. Keep sharing.
    website design

    ReplyDelete