Forum Moderators: coopster
what i am trying to do is from one form i select the amount of fields to be displayed, on the next page (which then displays it)
on this page it gets all the information and adds to mysql, sounds easy, so why am i struggling.
here are the fields
<br>Description <input type="text" name="description[]" size="20"><br>
Quantity <input type="text" name="quantity[]" size="20"><br>
Price <input type="text" name="price[]" size="20"><P>
that works fine.
havent really used an array before if thats what i should be using.
i assumed i would use something like this
$price[] = $_POST['price'];
all help is more than appreciated
Thank you.
Aaron
[edited by: jatar_k at 11:42 am (utc) on Oct. 22, 2007]
[edit reason] no urls thanks [/edit]
I can't be sure what exactly you are trying to achieve. Perhaps you might explain it better.
Description <input type="text" name="description[]" size="20"><br>
Quantity <input type="text" name="quantity[]" size="20"><br>
Price <input type="text" name="price[]" size="20"><P>
Can you tell me why you put the name of the input boxes in an array form?
Why are you trying to transfer the values basically from one array to another?
$price[] = $_POST['price'];
Habtom
i just put the form values as arays because i was trying to work around something that could work.
on the 1st page you select how many fields you want to be displayed on the next page.
then page 2 displays that many
page three should upload them to the database, but as they all have the same name how would i go about this? or how do i get it to recognise how many fields it should look for?
sorry if it sounds confusing!
Regards
but if u have only one predetermined type(text), you can get the variable by using the function array_keys() like below.
<?
$price = $_POST['price'];
foreach(array_keys($price) as $key){
echo "\$price[$key] = ".$price[$key]. "<br>\n";
}
?>
or try this loop if you know all your keys are going to be integers.
<?
for($i = 0; $ i < sizeof($price); $i++){
echo "\$price[$i] = ". $price[$i]. "<br>\n";
}
?>
If that is so then you dont need to worry as the $_GET/$_POST variables will only hold the information from that submission i.e.
page 1
There will be no $_POST or $_GET when this page is called.
Well there may be both, but as far as the workings of your script is concerned they are not being used.
page 2
The POST variables are coming from page 1 when this page is first called.
$_POST['price'] = '100';
$_POST['description'] = 'widget';
$_POST['quantity'] = '1';
page 3
the $_POST variables will contain whatever information was entered on page 2. So it may look completely different -
$_POST['description'] = 'widgets1';
$_POST['quantity'] = '10000';
So you dont need to worry about arrays.
d40sithui, a big thanks to you
this
for($i = 0; $i < sizeof($price); $i++)
{
echo "\$price[$i] = ". $price[$i]. "<br>\n";
}
regards
A
for($i = 0; $i < sizeof($price); $i++){
/* where MyTable is your table name
and MyPrice is the column name
*/
$query = "insert into MyTable (MyPrice) values(".$price[$i].")";
mysql_query($query);
}
my real concern is what your tables look like, and what kind of environment you're working in to allow such a big update to take place. looks like youll be updating alot. don't forget to validate your inputs before inserting.
thanks again,
i have changed the original code slightly so that instead of showing just the price it does the price description and quantity, (i just used price to get started), and now i will work on the db part.
it is going to be an invoice script!
so all the details are inputted, then you have the option at the end to view and print a pdf invoice...
but the reason i have done it to select how many items there are, is because it creates a random reference number and that needs to be the same on all items on the same invoice...
thanks once more
A