0

Hello everybody,
I want to have search option and the search result in one page, so I write the following code, but I dont know why after search there is no results displayed:

  • The file name is SearchInSide.php
<HTML> 
<BODY> 
<FORM Action="SearchInSide.php" Method="POST"> 
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000">
<p align="center">
<select name="metode" size="1">
<option value="name">Name</option>
<option value="telephone">Telephone</option>
<option value="birthday">Birthday</option>
</select> <input type="text" name="search" size="25"> &nbsp;<br>
Search database: <input type="submit" value="Go!!" name="Go"></p>
</td>
</tr>
</table>
</div>
</form>


<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>ID</b></td>
<td width="100"><b>Name</b></td>
<td width="70"><b>Telephone</b></td>
<td width="150"><b>Birthday</b></td>
</tr>

<?php
$hostname = "localhost"; // The Thinkhost DB server. 
$username = "root"; // The username you created for this database. 
$password = ""; // The password you created for the username. 
$usertable = "details"; // The name of the table you made. 
$dbName = "example"; // This is the name of the database you made. 

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database"); 
?> 
<?php

//error message (not found message)begins 
$XX = "No Record Found, to search again please try again"; 
//query details table begins

$query = mysql_query("SELECT * FROM details WHERE '$_POST[metode]' LIKE '$_POST[search]'% LIMIT 0, 50"); 
while ($row = @mysql_fetch_array($query)) 
{ 
$variable1=$row["id"];
$variable2=$row["name"]; 
$variable3=$row["telephone"]; 
$variable4=$row["birthday"];
//table layout for results 

print ("<tr>");
print ("<td>$variable1</td>"); 
print ("<td>$variable2</td>"); 
print ("<td>$variable3</td>"); 
print ("<td>$variable4</td>"); 
print ("</tr>"); 
}
//below this is the function for no record!!
if (!$variable1)
{ 
print ("$XX");
} 
//end 
?>
</table>
</center>
</BODY> 
</HTML>
3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by tanha
0

i have re written your code(hope this helps..)

<HTML>
<BODY>
<FORM Action="" Method="POST">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000">
<p align="center">
<select name="metode" size="1">
<option value="name">Name</option>
<option value="telephone">Telephone</option>
<option value="birthday">Birthday</option>
</select> <input type="text" name="search" size="25"> &nbsp;<br>
Search database: <input type="submit" value="Go!!" name="Go"></p>
</td>
</tr>
</table>
</div>
</form>


<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>ID</b></td>
<td width="100"><b>Name</b></td>
<td width="70"><b>Telephone</b></td>
<td width="150"><b>Birthday</b></td>
</tr>

<?php
if ($_POST)//user clicks go..
{
$hostname = "localhost"; // The Thinkhost DB server.
$username = "root"; // The username you created for this database.
$password = ""; // The password you created for the username.
$usertable = "details"; // The name of the table you made.
$dbName = "example"; // This is the name of the database you made.

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?php

//error message (not found message)begins
$XX = "No Record Found, to search again please try again";
//query details table begins

$query = mysql_query("SELECT * FROM details WHERE '$_POST[metode]' LIKE '$_POST[search]'% LIMIT 0, 50");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["id"];
$variable2=$row["name"];
$variable3=$row["telephone"];
$variable4=$row["birthday"];
//table layout for results

print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("</tr>");
}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
}
?>
</table>
</center>
</BODY>
</HTML>

0

thanx for replying,
But this seems the same as my code, and actually it is not working too...

0

the reason why the query did not execute bcoz it does not read the statement in your query
try this query $query = mysql_query("SELECT * FROM topics WHERE '" .$_POST. "' LIKE '%".$_POST."%' LIMIT 0, 50")
or die("error");
and for easy tracking of error always put die

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.