473,664 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple queries in one script

I am relatively new to PHP and MySQL. This is the first time I've tried
to use multiple queries in a single script.

I have the following PHP script which gets a Job Number from a search
form and generates a web page which displays the record for that job:

$username="root ";
$password="";
$database="foob ar";

$Searchterm = $_GET['JobNumber'];

mysql_connect(' localhost',$use rname,$password );
@mysql_select_d b($database) or die( "Unable to select database");

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

$result=mysql_q uery($query);
$num_results=my sql_num_rows($r esult);
$JobNumber=mysq l_result($resul t,$i,"JobNumber ");
$NSN=mysql_resu lt($result,$i," NSN");

echo various fields here

This part works fine.

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

I now want to list other jobs which use the same NSN on the same page
under that display. This is the script I'm using:

$query2="select * from jobs where NSN like $NSN";
$result=mysql_q uery($query2);
$num_results=my sql_num_rows($r esult);
$JobNumber=mysq l_result($resul t,$i,"JobNumber ");

echo query2; (returns the correct query, including the NSN)
echo $num_results (returns nothing)

$i=0;
while ($i < $num) {

echo various fields here (returns nothing)

$i++;
}

Can anyone tell me what I'm missing?


Feb 8 '06 #1
1 2455
Bob Sanderson wrote:

Hi Bob,
I am relatively new to PHP and MySQL. This is the first time I've tried
to use multiple queries in a single script.

I have the following PHP script which gets a Job Number from a search
form and generates a web page which displays the record for that job:

$username="root ";
$password="";
$database="foob ar";

$Searchterm = $_GET['JobNumber'];

mysql_connect(' localhost',$use rname,$password );
@mysql_select_d b($database) or die( "Unable to select database");

Ok so far.
$query="select * from jobs where JobNumber like $Searchterm";
This is very dangerous.
NEVER EVER thrust input originating from a form that is filled in by some
user.
You are wide open to the SQL-Injection attack this way.

If you have magic_quotes on, you are a lot safer, but please be sure what
you are doing...

$result=mysql_q uery($query);
$num_results=my sql_num_rows($r esult);
$JobNumber=mysq l_result($resul t,$i,"JobNumber ");
$NSN=mysql_resu lt($result,$i," NSN");
What is $i here?
$i defines the row to be retrieved, but you didn't give it any value.

echo various fields here

This part works fine.
good. :-)

Suprisingly because you didn't define $i.....

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

I now want to list other jobs which use the same NSN on the same page
under that display. This is the script I'm using:

$query2="select * from jobs where NSN like $NSN";
$result=mysql_q uery($query2);
$num_results=my sql_num_rows($r esult);
$JobNumber=mysq l_result($resul t,$i,"JobNumber ");
What is $i here?

echo query2; (returns the correct query, including the NSN)
That should be:
echo $query2;

You forgot the $
echo $num_results (returns nothing)
should return something if you fix the previous code. :-)

$i=0;
while ($i < $num) {
What is $num?
Do you mean $num_results???

echo various fields here (returns nothing)

$i++;
}

Can anyone tell me what I'm missing?


Fix the various mistakes. :-)
Good luck!

Regards,
Erwin Moller
Feb 8 '06 #2

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

Similar topics

2
10645
by: scott | last post by:
Hi, I'm having some trouble with something that should be relatively easy. I want to update multiple rows in one of my database tables simultaneously. In my table I have these values: imageID image_order I want to be able to modify the image_order column where imageID = imageID.
7
6197
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
4
16753
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from customers; I can execute each statement individually but get the 'you have an error in
2
2048
by: Jenny Zhang | last post by:
Hi, I am running OSDL-DBT3 test against PostgreSQL. I found performance difference between the runs even though the data and queries are the same. I tried to study this problem by getting execution plans at the beginning of each test. The following script gets execution plan for 22 queries, except query 15. i=1 while
0
8771
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11 Append Queries) when the Database is first opened, and then again anytime I invoke the Macro (somehow) after the database is already open. The latter function is useful, because the queries must be rerun every time data is added, deleted, or...
8
12609
by: Bob Sanderson | last post by:
I am relatively new to PHP and MySQL. This is the first time I've tried to use multiple queries in a single script. I have the following PHP script which gets a Job Number from a search form and generates a web page which displays the record for that job: $username="root"; $password=""; $database="foobar";
7
43134
by: Mintyman | last post by:
Hi, I'm working on a system migration and I need to combine data from multiple rows (with the same ID) into one comma separated string. This is how the data is at the moment: Company_ID Material 0x00C00000000053B86 Lead 0x00C00000000053B86 Sulphur 0x00C00000000053B86 Concrete
4
8864
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect the tables together with various queries using a unique id. My task is to generate reports from these tables dynamically. The user will select the data they want to see and the script will export a spreadsheet containing this data. I've got the...
4
2556
by: Akhenaten | last post by:
I am currently using enterprise manager to run multiple queries on a single table in a DB. I refresh these queries every few minutes. Due to the huge number of them I was looking for a better way (or should I just say "a way") to manage/save these queries so I can recall them easier/faster for monitoring purposes. Suggestions? TIA.
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8861
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2764
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 we have to send another system
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.