By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,842 Members | 2,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,842 IT Pros & Developers. It's quick & easy.

Whats wrong with this code

mmarif4u
P: 23
Hi Everyone.

I have html page coding:
HTML coding.....
---------------------------------------------------
<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>
--------------------------------------------------

Now Php Which have to search the database & Print results.
PHP Coding.....
--------------------------------------------------
<?
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;
}
?>

--------------------------------------------

The problem is that it cannot display the Results.
Whats wrong with this code.
Can anyone help me.
Thanks.
Oct 6 '06 #1
Share this Question
Share on Google+
2 Replies


100+
P: 268
Are u get the post value first and then working fine
Oct 6 '06 #2

bevort
P: 53
I think it has more to do with the $find var.
You check it against the upper() value in the database. But in this code you can not be sure thet the user typed only uppercase.
Make $find upper as well when comparing in the SQL

Next skip the hidden value "searching" and check on the submitbutton "Search"
like if ($Search) .......
this makes sure that hte user realy pressed the search button

Check also the query string you send to the database bu echoing it on screen.
Then check if this works in a query tool like PHPMyAdmin.

If you do not get results there you won't get them on screen.
Oct 6 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.