.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Search page in php

Posted By:satyapriyanayak       Posted Date: March 28, 2014    Points: 200    Category: General    URL: http://www.dotnetspark.com  

In this article we will know how to make a search page in php. For this we need a textbox and a button control. When the user enters any value for searching a record and click on button control then its corresponding values are shown in a tabular form below the page. It will show No Results found in case if there is no records exit for that search.
 

In this article we will know how to make a search page in php. For this we need a textbox and a button control. When the user enters any value for searching a record and click on button control then its corresponding values are shown in a tabular form below the page. It will show No Results found in case if there is no records exit for that search.


Table Structure

-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: May 20, 2012 at 06:39 PM
-- Server version: 5.0.45
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `Work`
--

-- --------------------------------------------------------

--
-- Table structure for table `employee`
--

CREATE TABLE `employee` (
  `id` int(11) NOT NULL auto_increment,
  `fullname` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  `state` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Dumping data for table `employee`
--

INSERT INTO `employee` (`id`, `fullname`, `address`, `city`, `state`) VALUES
(1, 'Raj', 'Inorbit Mall,Vashi', 'Pune', 'Maharastra'),
(2, 'Ravi', 'SV Road, Andheri (W)', 'Mumbai', 'Maharastra'),
(3, 'Barry', 'Krushal Commercial Complex,G.M. Road', 'Noida', 'UP'),
(4, 'Harry', 'Suburbia Mall, Linking Road, Bandra (W)', 'Delhi', 'Delhi'),
(5, 'Ian', 'Naman Plaza,S.V. Road, Opposite Shankar Lane', 'Nasik', 'Maharastra'),
(6, 'Sunny', 'Dynamix Mall, Y.J. Reality Ltd, Sant Dhyaneshwar Marg'


Code part

config.php


<?php
$host="localhost";
$username="root";
$password="";
$dbname="Work";
$con=mysql_connect("$host","$username","$password");
mysql_select_db("$dbname",$con);
?>

search.php

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search page in php</title>
</head>
<body>

<form method="post" id="frm" name="frm" action="search.php">
<table width="500" border="0">
  <tr>
    <td>Search page in php</td>
    <td>
      <input type="text"  name="fullname" id="fullname"/>    </td>
  </tr>

  <tr>
    <td>
      <input type="submit" name="Submit" value="Search" />   </td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
<?php
if($_REQUEST["Submit"]=="Search")
{
  $sql="select * from employee where fullname like '%$_REQUEST[fullname]%' OR address like '%$_REQUEST[fullname]%' OR city like '%$_REQUEST[fullname]%' OR state like '%$_REQUEST[fullname]%' OR id='$_REQUEST[fullname]'";
  $sql_row=mysql_query($sql);
  $num=@mysql_num_rows($sql_row);
  if($num > 0)
{
?>
<table width="500" border="1">
  <tr>
      <td>ID</td>
    <td>Name</td>
    <td>Address</td>
    <td>City</td>
    <td>State</td>
  </tr>
  <?php
  while($sql_res=@mysql_fetch_assoc($sql_row))
  {
  ?>
  <tr>
    <td><?php echo $sql_res["id"]; ?></td>
    <td><?php echo $sql_res["fullname"]; ?></td>
    <td><?php echo $sql_res["address"]; ?></td>
    <td><?php echo $sql_res["city"]; ?></td>
    <td><?php echo $sql_res["state"]; ?></td>
  </tr>
  <?php
  } ?>
</table>
<?php
}
else
{
?>
   <p>No Results found</p>
   <?php
   }
   ?>
<?php
}
?>
</body>
</html>

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend