Connecting Tech Pros Worldwide Help | Site Map

problem of variable between two pages

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:58 AM
Philippe Rousselot
Guest
 
Posts: n/a
Default 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

  #2  
Old July 17th, 2005, 04:58 AM
Tim Van Wassenhove
Guest
 
Posts: n/a
Default Re: problem of variable between two pages

In article <c6ecj0$1712$2@biggoron.nerim.net>, Philippe Rousselot wrote:[color=blue]
> 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 ?[/color]

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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.