Hi every one,
I have a little problem in php.
problem is that i want to search mysql table by php coding.
In php i want to use Drop down menu And a text field.
I have mysql table name is guestbook, now i use two entries
in dropdown menu (By Id,By name).and in the search text area
i type the any name selecting by name fom dropdown menu and then click on search button. Then it gave me the result in table format.
i Want the code for php how to retrieve data and what is the coding
for html form (Dropdown menu,text box,search button).

Can any one help me

Recommended Answers

All 7 Replies

so write it, theres not much to it.

1. need a db connection and database structure
2. need a form
3. need to wite some sql
4. need to format the html

look around, you will probibly find some examples or tutorials out there.

I try on that but i am not successful in php code can
u help in php coding.

If you have a specific question, yes I will help. If you want to hire a programmer then post in the jobs section.

Otherwise do your homework, and use google,yahoo,ask.com there are millions of sites out there that have tutorials and samples including this one.

thanks for reply.
I have html page coding:

<form name="search" method="post" action="Search.php">
Seach for: <input type="text" name="find" /> in 
<Select NAME="field">
<Option VALUE="fname">First Name</option>
<Option VALUE="lname">Last Name</option>
<Option VALUE="info">Profile</option>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />

Now Php Which have to search the database & Print results.

if ($searching =="yes") 
echo "<h2>Results</h2><p>"; 

if ($find == "") 
echo "<p>You forgot to enter a search term"; 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 
$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find); 

$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); 

while($result = mysql_fetch_array( $data )) 
echo $result['fname']; 
echo " "; 
echo $result['lname']; 
echo "<br>"; 
echo $result['info']; 
echo "<br>"; 
echo "<br>"; 
if ($anymatches == 0) 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
echo "<b>Searched For:</b> " .$find; 

The problem is that it cannot display the Results.
Whats wrong with this code.
Can u help me.

Are you getting an error or just no data returned?
try this

$sql = "SELECT * FROM users WHERE upper($field) LIKE'%".$find."%'"
$data = mysql_query($sql);

Looks like you put the find variable inside of single quotes which treat it as literal. mysql is looking for $find and not the contents of that variable.
The die function will exit the script and echo out the query, if it looks good then comment out the die and continue.

I just try ur code but it also doesnt return results.
I mean that the page is blank Nothing is displayed.

make sure you have errors turned on

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

It sounds like youre script is failing before it even gets to the die() function.

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.