There is a little bit prob with my code,
My Prob: When i type name or place etc in search bar it show me the entire data stored in database, i need it show what i searching for...

script for Search:

<div id="wb_Form1" style="position:absolute;width:864px;height:147px;">
<form name="q" method="get" action="test-result.php" id="Form1">
<input type="text" id="Editbox1" style="position:absolute;left:13px;top:7px;width:836px;height:50px;line-height:50px;z-index:5;" name="query" value="" title="Test" placeholder="Type your place or address to find">
<input type="submit" id="Button1" name="" value="Search" style="position:absolute;left:322px;top:76px;width:239px;height:53px;z-index:6;">
</form>
</div>

and my action script (test-result.php)

<Strong><Font size="3">
<?php
$host="localhost"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="search"; // Database name 
$tbl_name="list"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>

<table width="" border="0" cellspacing="5" cellpadding="0">
<tr>
<td>
<table width="" border="1" cellspacing="5" cellpadding="3">

<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Type</strong></td>
<td align="center"><strong>Address</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><? echo $rows['Name']; ?></td>
<td><? echo $rows['Type']; ?></td>
<td><? echo $rows['Address']; ?></td>

<td align="center"><a href="Show.php?id=<? echo $rows['id']; ?>">View Details</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

i made the following changes result get error:

New Change:

$sql = mysql_query("SELECT * FROM company WHERE (`Name` LIKE '%".$query."%') OR (`Type` LIKE '%".$query."%')") or die(mysql_error());
$result=mysql_query($sql);
?>

Warning: mysql_query() expects parameter 1 to be string, resource given in /home/swatcorp/public_html/search/test-result.php on line 157

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/test-result.php on line 172

$sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
?>

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/test-result.php on line 172

i correct the warning error, but the main error is they display the entire data srored in datavase i want only searched data ?

Any development

Try doing it this way;

    $sql = mysql_query("SELECT * FROM company WHERE Type LIKE '%".$query."%'") or die(mysql_error());
    ?>
   $sql = mysql_query("SELECT * FROM company WHERE Type LIKE '%".$query."%'") or die(mysql_error());
    ?>

get this:

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/test-result-shwoing-name-ok.php on line 209

Try this and tell us what it returns:

$myQuery = "SELECT * FROM `company` WHERE `Type` LIKE '%$query%'";
$sql = mysql_query($myQuery) or die($myQuery . '<br/>' . mysql_error());

Chage and result is :

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/test-result-shwoing-name-ok.php on line 210

any body

The code i post on top thats the full code other is just style sheet.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Search About Location</title>
<meta name="description" content="Global Genrate.">
<meta name="keywords" content="ask, Place">
<meta name="author" content="Notepad ++">
<meta name="robots" content="INDEX, FOLLOW">
<meta name="revisit-after" content="1 Day">
<meta name="generator" content="">
<style>
html, body
{
   height: 100%;
}
div#space
{
   width: 1px;
   height: 50%;
   margin-bottom: -367px;
   float:left
}
div#container
{
   width: 970px;
   height: 734px;
   margin: 0 auto;
   position: relative;
   clear: left;
}
body
{
   background-color: #FFFFFF;
   color: #000000;
   font-family: Arial;
   font-size: 8px;
   line-height: 1.1875;
   margin: 0;
   padding: 0;
}
</style>
<style>
@-webkit-keyframes animate-border
{
   0% { border-color: #000000;  }
   100% { border-color: #FF0000;  }
}
@-moz-keyframes animate-border
{
   0% { border-color: #000000;  }
   100% { border-color: #FF0000;  }
}
@-o-keyframes animate-border
{
   0% { border-color: #000000;  }
   100% { border-color: #FF0000;  }
}
@-ms-keyframes animate-border
{
   0% { border-color: #000000;  }
   100% { border-color: #FF0000;  }
}
@keyframes animate-border
{
   0% { border-color: #000000;  }
   100% { border-color: #FF0000;  }
}
a
{
   color: #0000FF;
   text-decoration: underline;
}
a:visited
{
   color: #800080;
}
a:active
{
   color: #FF0000;
}
a:hover
{
   color: #0000FF;
   text-decoration: underline;
}
</style>
<style>
#Image3
{
   border: 0px #000000 solid;
}
#Image6
{
   border: 0px #000000 solid;
}
#Image4
{
   border: 0px #000000 solid;
}
#Image1
{
   border: 0px #000000 solid;
}
#wb_Form1
{
   background-color: transparent;
   border: 0px #000000 solid;
}
#Editbox1
{
   border: 1px #565554 solid;
   background-color: #FFFFFF;
   color :#000000;
   font-family: Arial;
   font-weight: bold;
   font-style: italic;
   font-size: 27px;
   padding: 0px 0px 0px 2px;
   text-align: center;
   vertical-align: middle;
   -webkit-animation: animate-border 500ms ease-in-out 0ms infinite normal;
   -moz-animation: animate-border 500ms ease-in-out 0ms infinite normal;
   -ms-animation: animate-border 500ms ease-in-out 0ms infinite normal;
   animation: animate-border 500ms ease-in-out 0ms infinite normal;
}
#Button1
{
   border: 0px #A9A9A9 solid;
   -moz-border-radius: 2px;
   -webkit-border-radius: 2px;
   border-radius: 2px;
   background-color: transparent;
   background-image: url(images/page1_Button1_bkgrnd.png);
   background-repeat: repeat-x;
   background-position: left top;
   color: #FFFFFF;
   font-family: Arial;
   font-weight: bold;
   font-size: 27px;
}
#Layer2
{
   background-color: #FF8C00;
}
#Layer1
{
   background-color: #FF8C00;
}
#wb_Text2 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: left;
}
#wb_Text2 div
{
   text-align: left;
}
</style>
</head>
<body>
<div id="Layer2" style="position:absolute;text-align:left;left:0px;top:0px;width:100%;height:24px;z-index:3;" title="">
</div>
<div id="Layer1" style="position:absolute;text-align:center;left:0px;top:707px;width:100%;height:24px;z-index:4;" title="">
<div id="Layer1_Container" style="width:973px;position:relative;margin-left:auto;margin-right:auto;text-align:left;">
<div id="wb_Text2" style="position:absolute;left:2px;top:4px;width:968px;height:16px;z-index:2;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;"><strong>Submit your content&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Support&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Complaint&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Suggestion&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Privacy&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; FAQ&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Admin&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Advertising</strong></span></div>
</div>
</div>
<div id="space"><br></div>
<div id="container">
<div id="wb_Image3" style="position:absolute;left:11px;top:160px;width:51px;height:45px;z-index:5;">
<img src="images/company.png" id="Image3" alt="" style="width:51px;height:45px;"></div>
<div id="wb_Image6" style="position:absolute;left:398px;top:155px;width:35px;height:44px;z-index:6;">
<img src="images/images%20%285%29.jpg" id="Image6" alt="" style="width:35px;height:44px;"></div>
<div id="wb_Image4" style="position:absolute;left:184px;top:157px;width:51px;height:45px;z-index:7;">
<img src="images/images%20%284%29.jpg" id="Image4" alt="" style="width:51px;height:45px;"></div>
<div id="wb_Image1" style="position:absolute;left:0px;top:24px;width:374px;height:113px;z-index:8;">
<img src="images/new%20sr.jpg" id="Image1" alt="" style="width:374px;height:113px;"></div>
<div id="wb_Form1" style="position:absolute;left:373px;top:40px;width:594px;height:110px;z-index:9;">
<form name="q" method="get" action="Result.php" id="Form1">
<input type="text" id="Editbox1" style="position:absolute;left:28px;top:8px;width:548px;height:44px;line-height:44px;z-index:0;" name="query" value="" title="Powerd By: Swat Corporation" placeholder="Type business, company, place, organization name ?">
<input type="submit" id="Button1" name="" value="Search" style="position:absolute;left:201px;top:70px;width:185px;height:34px;z-index:1;">
</form>
</div>
<div id="Html1" style="position:absolute;left:0px;top:190px;width:967px;height:297px;z-index:10">
<Strong><Font size="3">
<?php
$host="host"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="db"; // Database name 
$tbl_name="company"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>

<table width="" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="" border="1" cellspacing="0" cellpadding="3">

<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Type</strong></td>
<td align="center"><strong>Address</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><a href="Get-Details.php?id=<? echo $rows['id']; ?>">View Details</a></td>
<td><? echo $rows['Type']; ?></td>
<td><? echo $rows['Address']; ?></td>

</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?></div>
</div>
</body>
</html>
$sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
$result=mysql_query($sql);
if($result != $query)
{
 echo "data not found";
}

else
{
echo $result;
}

og goto Click Here

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
$result=mysql_query($sql);
if($result != $query)
{
 echo "data not found";
}
else
{
echo $result;
}

<table width="" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="" border="1" cellspacing="0" cellpadding="3">

<tr>
<td align="center"><strong>Business Name</strong></td>
<td align="center"><strong>Business Type</strong></td>
<td align="center"><strong>Address</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><a href="Get-Details.php?id=<? echo $rows['id']; ?>">['Name']</a></td>
<td><? echo $rows['Type']; ?></td>
<td><? echo $rows['Address']; ?></td>

</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

Parse error: syntax error, unexpected '<' in /home/swatcorp/public_html/search/page1.php on line 212

And which one is your line 212?

Have you tried doing it this way?? coz myn does not give me any errors ...

<?php
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
    $result=mysql_query($sql);
    if($result != $query)
    {
    echo "data not found";
    }
    else
    {
    echo $result;
    }
    ?>
    <table width="" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td align="center"><strong>Business Name</strong></td>
    <td align="center"><strong>Business Type</strong></td>
    <td align="center"><strong>Address</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><a href="Get-Details.php?id=<? echo $rows['id']; ?>"><?php echo $rows['Name']; ?></a></td>
    <td><? echo $rows['Type']; ?></td>
    <td><? echo $rows['Address']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>

W8 im checking.

I try this:

<Strong><Font size="3">
<?php
$host="host"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="db"; // Database name 
$tbl_name="company"; // Table name 

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
    $result=mysql_query($sql);
    if($result != $query)
    {
    echo "data not found";
    }
    else
    {
    echo $result;
    }
    ?>
    <table width="" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td align="center"><strong>Business Name</strong></td>
    <td align="center"><strong>Business Type</strong></td>
    <td align="center"><strong>Address</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><a href="Get-Details.php?id=<? echo $rows['id']; ?>"><?php echo $rows['Name']; ?></a></td>
    <td><? echo $rows['Type']; ?></td>
    <td><? echo $rows['Address']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>

Result is This:

Warning: mysql_query() expects parameter 1 to be string, resource given in /home/swatcorp/public_html/search/page1.php on line 201

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/page1.php on line 221
Business Name   Business Type   Address

Line 12 and 13 are conflicting (as I said before). You still have two mysql_query's where there should be a single one.

Look This my Search Code:

</head>
<body>
<div id="space"><br></div>
<div id="container">
<div id="wb_Image1" style="position:absolute;left:237px;top:85px;width:468px;height:142px;z-index:2;">
<img src="images/new%20sr.jpg" id="Image1" alt="" style="width:468px;height:142px;"></div>
<div id="wb_Form1" style="position:absolute;left:35px;top:222px;width:864px;height:147px;z-index:3;">
<form name="query" method="get" action="page1.php" id="Form1">
<input type="text" id="Editbox1" style="position:absolute;left:13px;top:7px;width:836px;height:50px;line-height:50px;z-index:0;" name="query" value="" title="" placeholder="Type">
<input type="submit" id="Button1" name="" value="Search" style="position:absolute;left:322px;top:76px;width:239px;height:53px;z-index:1;">
</form>
</div>
</div>
</body>
</html>

And This is Action Page Script:

<Strong><Font size="3">
<?php
$host="host"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="company"; // Table name 

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
    $result=mysql_query($sql);
    if($result != $query)
    {
    echo "data not found";
    }
    else
    {
    echo $result;
    }
    ?>
    <table width="" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td align="center"><strong>Business Name</strong></td>
    <td align="center"><strong>Business Type</strong></td>
    <td align="center"><strong>Address</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><a href="Get-Details.php?id=<? echo $rows['id']; ?>"><?php echo $rows['Name']; ?></a></td>
    <td><? echo $rows['Type']; ?></td>
    <td><? echo $rows['Address']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>

And This is the error:

Warning: mysql_query() expects parameter 1 to be string, resource given in /home/swatcorp/public_html/search/page1.php on line 201
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/page1.php on line 221
Business Name   Business Type   Address

So what is wrong with this?

You are executing the query twice, here;

 $sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
$result=mysql_query($sql);

Choose either to execute it like this;

 $sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());

Or like this;

 $sql = "SELECT * FROM company WHERE `Type` LIKE '%".$query."%'";
$result=mysql_query($sql)or die(mysql_error());

That should do it.

I chage it to inly one query like this:

// Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql = mysql_query("SELECT * FROM company WHERE (`Type` LIKE '%".$query."%')") or die(mysql_error());
    if($result != $query)
    {
    echo "data not found";
    }
    else
    {
    echo $result;
    }
    ?>
    <table width="" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td align="center"><strong>Business Name</strong></td>
    <td align="center"><strong>Business Type</strong></td>
    <td align="center"><strong>Address</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><a href="Get-Details.php?id=<? echo $rows['id']; ?>"><?php echo $rows['Name']; ?></a></td>
    <td><? echo $rows['Type']; ?></td>
    <td><? echo $rows['Address']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>

Now this time get this result:
No rsult + Warning?

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/swatcorp/public_html/search/page1.php on line 220
Business Name   Business Type   Address

$result doesn't have a value, since you assigned the query result to $sql, so change $sql to $result

You are checking the wrong result. You should have this;

    $sql = "SELECT * FROM company WHERE Type LIKE '%".$query."%'";
    $result=mysql_query($sql)or die(mysql_error());

    if(!$result)
    {
    echo "data not found";
    }
    else
    {
    // Display the results
    }

its worked but another and old prob return?

When i search for indivisval it show me all stored data from table.
i.e: when i type in search abc etc they show me all stored records from table

Which code are you using. Show us the code.

<?php
$host="host"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="company"; // Table name 

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
 $sql = "SELECT * FROM company WHERE Type LIKE '%".$query."%'";
    $sql=mysql_query($sql)or die(mysql_error());
    if(!$sql)
    {
    echo "data not found";
    }
    else
    {
    // Display the results
    }
    ?>
    <table width="" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td align="center"><strong>Business Name</strong></td>
    <td align="center"><strong>Business Type</strong></td>
    <td align="center"><strong>Address</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($sql)){
    ?>
    <tr>
    <td><a href="Get-Details.php?id=<? echo $rows['id']; ?>"><?php echo $rows['Name']; ?></a></td>
    <td><? echo $rows['Type']; ?></td>
    <td><? echo $rows['Address']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.