473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Whats wrong with this code

mmarif4u
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
2 1441
vssp
268 100+
Are u get the post value first and then working fine
Oct 6 '06 #2
bevort
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

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

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
3
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."',...
4
by: asdf | last post by:
Hello! Can someone tell me whats wrong with this piece of code: Option Compare Database Option Explicit Sub retrieve() Dim rst As ADODB.Recordset Dim i As Integer
1
by: aa | last post by:
When I am reading from local disk (d:), everithing is OK, but then I am reading from map disk I am geting the this error. Whats wrong. Thanks Server Error in '/Extra' Application....
3
by: mahsa | last post by:
Hi do you know whats wrong with this code? <asp:HyperLink id="HLink_Help" runat="server" NavigateUrl='<%# "javascript:window.open('comments.aspx?id=1,width=500,height=600, scrollBars=yes');"...
4
by: blah | last post by:
Hello everyone, Ive been trying to get my application to "click" on a button in another application using SendMessage, Ive gotten this far but Im not sure whats wrong with this code, here is the...
7
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell...
1
by: Abubakar | last post by:
Hi, In my application, Some of my thread gets stuck somewhere. The vs2k5 debugging "Thread" window shows that stuck thread and I can I dentify it. In its Name column the following text is...
5
by: islayer | last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just...
5
by: hiqu | last post by:
This issue is driving me nuts and not able to figure out whats wrong. I've this code in my firefox extension. Firefox always hangs and reports the script is busy. if I introduce a break...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.