Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Help Please

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Help Please

Postby AaaDee » Tue Oct 29, 2002 3:12 am

Hi, i have a form that gives you an option of how many text boxes you want in the next page!

ie

Amount of Text Boxes?: <input type="text" name="skill_amount3">

<input type="submit">

That goes to the next page and say you enter "3" in the text box, it gives you "3" text boxes with the SAME value for each textbox.

Ive done it like

for ($i = 0 ; $i < $skill_amount3; $i++)

{

echo "

Text Box: <input type=\"text\" name=\"box\">

";

}

Then i want to pass the results over to the next page!! But BECAUSE i dont know how many text boxes a users going to be using i can only do the

for ($i = 0 ; $i < $skill_amount3; $i++)

{

echo ""

}

again.

Ok, now to the problem!!

Hard Work Huh!

The users asks for 3 text boxes the forms gives them that, and they can right there text in the text box!

This submits the entries, and on the FINAL page (With me still? :? )

Gives me 3 results!

BUT 8O

all the answers are the values from the last text box!! So its like the 2nd box value overwrites the first, and the 3rd box value overwrites the 2nd and gives me 3 boxes with the same answers!!

The results i put in were!!

AB001
Value 1
AB002
Value 2

and only AB002 and Value 2 came back TWICE!!

Can anybody help please??

This is quite urgent!

Hope you can,

Thanks VERY much for your time

Adam
User avatar
AaaDee
New php-forum User
New php-forum User
 
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield

Postby DoppyNL » Tue Oct 29, 2002 3:19 am

When you create the boxes you give them all the same name (box):
Code: Select all
for ($i = 0 ; $i < $skill_amount3; $i++)

{

echo "

Text Box: <input type=\"text\" name=\"box\">

";

}

This will cause that only the last value will be transfered back to the server.
Give them all a different name like this:
Code: Select all
echo "Text Box: <input type=\"text\" name=\"box" . $i . "\">";

or in my way of coding:
Code: Select all
print('Text Box: <input type="text" name="box' . $i . '">');


Greetz Daan
DoppyNL
 

Postby AaaDee » Tue Oct 29, 2002 3:27 am

Hi,

That gave me different values but not the answer i wrote in

I put in

AB001

AB002

AB003

and it came back with

box20

box21

box22

i also changed the values on the result page to box" . $i . "

Do i need to do anything else??

Thanks a lot

Adam
User avatar
AaaDee
New php-forum User
New php-forum User
 
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield

Postby Wacko2019 » Tue Oct 29, 2002 3:28 am

When you make use of a loop and variable text boxes, it should work.

I presume you have 2 forms on your webpage and when you've pressed the submit button on the first form, the other form appears with there 3 text boxes.

I suggest you do something like this:

In the first form you have something like this:

<input type="text" name="amount">

in this field the user can enter his amount of text boxes.

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

On the second form you begin with a loop:

<php
$counter = 0;
$temp = 0;
while ($counter != $amount)
{
$temp = ($temp + 1);
?>
<input type="text" name="description$temp" value="">
<php
$counter = ($counter + 1);
}
?>

When you do it like this, it should work.............. :D

Greetz Helgo Rongen.
Wacko2019
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Oct 27, 2002 10:18 am
Location: Netherlands

Postby DoppyNL » Tue Oct 29, 2002 3:36 am

Code: Select all
?>
<input type="text" name="description$temp" value="">
<php

This doesn't work as was intended! The string "$temp" will end up in your page, not the value of $temp.
simply use a single print line, it improves readability of your script A LOT and speed issues for such a short bit of text isn't an issue.
Also, the "value" attribute is not neccesary when it is empty. The browser will make an empty input field when it is not supplied.
So you might want to change the quoted code into:
Code: Select all
print('<input type="text" name="description' . $temp . '">');


I can't seem to find out what is actually going wrong.
You might want to take a closer look at the generated form-page to see if it is generated correctly (open in your browser and view the source)
You can also use "printr($_POST);" in the last page to see what is actually posted by the form.

Greetz Daan
DoppyNL
 

Postby Jay » Tue Oct 29, 2002 6:00 am

Just use name="box[]" - that'll transfer all the variables onto the next page into an array and you can just go through the array listing all the elements!
Jay
 


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 9 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron