473,385 Members | 1,942 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,385 software developers and data experts.

problem of variable between two pages

Hi,

On a page, I have a form with a variable number of fields.

to print these fields, I have such a code :
while ($i !=0){
echo '<td> <input type="text" name="component'.$i.'" size="20"
value="" maxlength="70"> </td><br>
<td> <input type="text" name="quantity'.$i.'" size="20"
value="" maxlength="70"><br>
</td> </tr><tr>' ;
$i = $i - 1 ;
}

I then get variables such as component1, component2, etc. and quantity1,
quantity2, etc.

next page I want to enter these values into a MySQL table.

I am therefore passing from one page to another the value of the variables,
and some others.
I get the following code :
<?
$i = $nombercomponent ;
$db = mysql_connect('localhost', '', '');
mysql_select_db('recipe',$db);
while ($i !=0){
$sql = "INSERT INTO component VALUES('','','$ingr','$quant')";
mysql_query($sql) or die('Error !'.$sql.'<br>'.mysql_error());
$i = $i - 1 ;
}
mysql_close();
?>

How to have $ingr and $quant corresponding to all component and quantity
variable there number is variable ?
Thanks in advance

Philippe
Jul 17 '05 #1
1 1450
In article <c6***********@biggoron.nerim.net>, Philippe Rousselot wrote:
Hi,

On a page, I have a form with a variable number of fields.

to print these fields, I have such a code :
while ($i !=0){
echo '<td> <input type="text" name="component'.$i.'" size="20"
value="" maxlength="70"> </td><br>
<td> <input type="text" name="quantity'.$i.'" size="20"
value="" maxlength="70"><br>
</td> </tr><tr>' ;
$i = $i - 1 ;
}

I then get variables such as component1, component2, etc. and quantity1,
quantity2, etc.

next page I want to enter these values into a MySQL table.

I am therefore passing from one page to another the value of the variables,
and some others.
I get the following code :
<?
$i = $nombercomponent ;
$db = mysql_connect('localhost', '', '');
mysql_select_db('recipe',$db);
while ($i !=0){
$sql = "INSERT INTO component VALUES('','','$ingr','$quant')";
mysql_query($sql) or die('Error !'.$sql.'<br>'.mysql_error());
$i = $i - 1 ;
}
mysql_close();
?>

How to have $ingr and $quant corresponding to all component and quantity
variable there number is variable ?


What is the version of php you are using? If you would have bothered to
type in your question in the google search groups box, you would have
found the answer a zillion times. (hint: register globals)

It's probably not a bad idea to perform a mysql_escape_string on the
values you are trying to insert into your database.

--
http://home.mysth.be/~timvw
Jul 17 '05 #2

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

Similar topics

1
by: farooqazeem | last post by:
Hi guys, I’m facing some problem can u solve it. Problem is: I’m giving user Id and password in (Login_sess.asp) and submit it to page (sess_test.asp). I am setting session variable...
4
by: Trevor Best | last post by:
I have a report that's fairly simple, page headers and footers, detail has a subreport in (can vary in length). The customer wanted a signature block for them, their client and 3rd party. This was...
1
by: Steve Wark | last post by:
If I create two aspx pages, place three text boxes (working with VS .net 2003 and web form controls) and a button on both forms. On the first page, the button is set to use the "onClick" to open...
20
by: Hemant Shah | last post by:
Folks, I spent better part of morning debugging a problem and it turned out to be DB2_USE_ALTERNATE_PAGE_CLEANING registry variable. I am running DB2 8.2 on AIX 5.3 system: # oslevel...
2
by: RoomfulExpress | last post by:
The only problem I'm having with this code is when there are no values returned for the query, it is still allowing you to see and click the 'Next>>'. It disappears when there is at least one return...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...

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.