Hi All, I Have a PHP Searching Code it have some problem it only connet to database but does not show any result..........

PHP Code is :-
Search.php

<HTML> 
<BODY> 
<FORM Action="/Search.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
if ($_POST['Go'])//user clicks go..
{
$dbh=mysql_connect ("localhost", "kuchcity_hemant", "hemgoyal") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("kuchcity_example");
?> 
<?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>

any one plz help me......

Hi
hemgoyal

you have this one in line 3 which i marked it in red move it to small litter and chick and let me know

<FORM Action="/Search.php" Method="POST">

Dear i am Doing Your Tricx But my Problem doe's not solved yet.... Plz Dear Give me Solution of my problem.

SELECT * FROM details WHERE '$_POST[metode]' LIKE '$_POST[search]'% LIMIT 0, 50

I guess $_POST is the column name ? Print out the query, execute it in phpmyadmin/ mysql console. Check the result. Oh, also, remove the @ symbol from

$row = @mysql_fetch_array($query)

Dear i am Doing Your Tricx But my Problem doe's not solved yet.... Plz Dear Give me Solution of my problem.

Sorry can't help more cuz i don't have the Database you use i just uploaded the "search.php" file to my site and got the issue of the first file reads "Search.php"
and when i typed a name it turned me to "search.php" but with a db error cuz there i cant call your database :P
if you can post it i think i can help and do try what nav33n said
still around you :cool:
brb

No Dear, in this script line
SELECT * FROM details WHERE '$_POST[metode]' LIKE '$_POST[search]'% LIMIT 0, 50 there metode is not not any coloumn this is a POST METHOD.

Then your query is wrong. What exactly are you trying to do with that query ?

Dear i Want to Create a Search page so any one user can search data from this page. if u know right coading plz post here.

Your query should be SELECT * FROM details WHERE columnname LIKE '$_POST[search]'% LIMIT 0, 50

try printing the sql statement before executing it
that could help u

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.