944,008 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7912
  • PHP RSS
Oct 4th, 2006
0

Filtering My sql through Php using drop down menu and text field

Expand Post »
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
Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmarif4u is offline Offline
7 posts
since Oct 2006
Oct 4th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

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.
Last edited by tgreer; Oct 6th, 2006 at 5:33 pm. Reason: Removed unnecessary quote block.
Reputation Points: 10
Solved Threads: 2
Junior Poster
sn4rf3r is offline Offline
133 posts
since Sep 2006
Oct 4th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

I try on that but i am not successful in php code can
u help in php coding.
Thanks
Last edited by mmarif4u; Oct 4th, 2006 at 11:29 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmarif4u is offline Offline
7 posts
since Oct 2006
Oct 5th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

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.
Last edited by tgreer; Oct 6th, 2006 at 5:32 pm. Reason: Removed unnecessary quote block.
Reputation Points: 10
Solved Threads: 2
Junior Poster
sn4rf3r is offline Offline
133 posts
since Sep 2006
Oct 5th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

thanks for reply.
ok
I have html page coding:

[html]<h2>Search</h2>
<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>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>[/html]

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

[php]<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
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>";
}

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

echo "<b>Searched For:</b> " .$find;
}
?>[/php]


The problem is that it cannot display the Results.
Whats wrong with this code.
Can u help me.
Thanks.
Last edited by tgreer; Oct 6th, 2006 at 12:36 pm. Reason: Added code tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmarif4u is offline Offline
7 posts
since Oct 2006
Oct 6th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

Are you getting an error or just no data returned?
try this
PHP Syntax (Toggle Plain Text)
  1. $sql = "SELECT * FROM users WHERE upper($field) LIKE'%".$find."%'"
  2. die($sql);
  3. $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.
Last edited by tgreer; Oct 6th, 2006 at 5:32 pm. Reason: Removed unnecessary quote block.
Reputation Points: 10
Solved Threads: 2
Junior Poster
sn4rf3r is offline Offline
133 posts
since Sep 2006
Oct 7th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

I just try ur code but it also doesnt return results.
I mean that the page is blank Nothing is displayed.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmarif4u is offline Offline
7 posts
since Oct 2006
Oct 9th, 2006
0

Re: Filtering My sql through Php using drop down menu and text field

make sure you have errors turned on
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  3. ?>

It sounds like youre script is failing before it even gets to the die() function.
Reputation Points: 10
Solved Threads: 2
Junior Poster
sn4rf3r is offline Offline
133 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP includes & variables
Next Thread in PHP Forum Timeline: Hand Writing Poll Results Scripts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC