473,511 Members | 15,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search Term Not Passing to Output Form

I have a search form from which I hope to be able to select a record by
field JobNumber and display it with an output form titled test.php

<html>
<head>
<title>Job Database Search</title>
</head>
<body style='font-family: Geneva, Arial, Helvetica, sans-serif;'>
Enter Job Number:
<form action="test.php" method="post">
<input type="text" name="searchterm">
<input type="submit" name="Send">
</form>
</body>
</html>

The query on the output form (test.php) is as follows and returns a blank
output:

$query="select * from jobs where JobNumber like '$searchterm'";

The problem I'm having is that the searchterm variable does not appear to
be passing to the output form. I know that I am connecting to the database
and that the query is fundamentally correct because I can access the record
I want by substituting a real Job Number for the variable.

Any ideas?
Jan 4 '06 #1
2 1316
"Bob Sanderson" <sa*****@LUVSPAMsandmansoftware.com> wrote in message
news:Xn**********************************@207.69.1 89.191...
$query="select * from jobs where JobNumber like '$searchterm'";

The problem I'm having is that the searchterm variable does not appear to
be passing to the output form.


The first troubleshooting step anytime you are creating SQL strings
programmatically is to output the finished SQL string. This allows you to
spot unbalanced quotes, unanticipated whitespace, etc.

BTW, the example you give above is a classic "SQL injection" security flaw.
What happens if a malicious user enters a string into your input form such
as:

nomatch'; delete from jobs;

Another troubleshooting method is to cut & paste the finished $query string
into the mysql client (or MySQL Query Browser) and see if that statement
produces the query results you intend.

Also, make sure your PHP code tests for error status returned from the query
execution, and displays any error messages to the HTML output.

Regards,
Bill K.
Jan 4 '06 #2
On Wed, 04 Jan 2006 17:33:52 +0000, Bob Sanderson wrote:
The query on the output form (test.php) is as follows and returns a blank
output:

$query="select * from jobs where JobNumber like '$searchterm'";


First off, re-read Bill's advice even if you've already read it - it's
very important.

Do you have "register_globals" turned on?

It's not set by default on PHP now (and it's not a good idea either) so
you should be using the new superglobals:

$query="select * from jobs where JobNumber like '$_POST[searchterm]'";

Actually that isn't absolutely correct (as searchterm could be define()d
to be something else), but it's what 99.9% of PHP programmers use and is
fine as long as you are aware of defines.

Cheers,
Andy
--
Andy Jeffries | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Jan 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5007
by: leegold2 | last post by:
Commonly done, eg. you enter a word in a search engine and when a hit-page comes up the search word(s) are highlighted. I'm doing a fulltext search that works well but I've tried a few "packaged...
4
2665
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
1
1625
by: Sheau Wei | last post by:
Below is my search engine code. I realize that the function was very limitied because i cannot searching the "NamaPealatan"(name of tools) compatible to the either categories Operasi or Balai or...
3
2205
by: Sheau Wei | last post by:
This is the search engine code that i create, but it was error and didnt come out the result. Cn u help me to check what wrong with my code? Thanks <Table cellspacing=1 cellPadding=1...
1
2507
by: cglewis03 | last post by:
Hello, I am trying to build a search form with several different options to choose from. Currently it is set up to open within the same window if a single option is selected and open within a...
10
2257
by: jonathan184 | last post by:
Hi I tried getting this to work through dreamweaver but it did not. So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me...
3
3961
by: suek | last post by:
I have a table with over 4000 records to search upon, and the users don't like a combo box. So what I have been trying to do for the last twelve hours is do some code to get a text box to search. ...
5
2755
by: reddem0n | last post by:
Hello, I've been working on trying to figure out how to script something where if a user enters more then one search term in the same fieldbox, it would query both of them and output it to a cf...
0
7245
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
7427
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...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
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,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.