| Ultrashock Forums
• PHP - POST an array? |
Member Blogs | ||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
1 Blog Entries
13 Creative Assets
|
2008-07-08
#2 |
||
|
13 Blog Entries
|
2008-07-08
#3 |
||
|
Hmm I suppose so. Except the value must be whatever is stored in $_POST[ "fruit" ][ i ]. So would this work? Code:
<form ... >
<input type="text" name="fruit[]" value="fruit[]"/>
<input type="text" name="fruit[]" value="fruit[]"/>
<input type="text" name="fruit[]" value="fruit[]"/>
</form>Code:
<?php
echo( $_POST[ "fruit" ][ 0 ] );
echo( $_POST[ "fruit" ][ 1 ] );
echo( $_POST[ "fruit" ][ 2 ] );
?>
I suppose I can also declare the session as: Code:
$_SESSION['fruit'] = $fruit; |
|
1 Blog Entries
13 Creative Assets
|
2008-07-08
#4 |
||
|
That wouldn't work because all of your posted input values would be "fruit[]". I took another look at your PHP code and spotted a few errors so I fixed them, see if this works for you now... Code:
<?php
foreach( $quant as $value )
{
$_SESSION[ $value ] = $_POST[ $value ];
echo( "<input type=\"text\" name=\"{$value}\" size=\"1\" maxlength=\"2\" value=\"{$value}\">" );
}
?>
|
|
13 Blog Entries
|
2008-07-08
#5 |
||
|
Still not quite working. $quant is an array that holds the form inputs yes. Well, starting back from the beginning, here's sort of the big picture: Code:
<?php
$_SESSION["quant"] = $_POST["quant"];
// get data
$filestream = file_get_contents("$order_menu1");
$line_separated = explode("\n",$filestream); // separate by line
for ($i = 0; $i < sizeof($line_separated); $i++){
// separate line by item
$comma_separated = explode(",",$line_separated[$i]);
$item[$i] = $comma_separated[0];
$price[$i] = $comma_separated[1];
$description[$i] = $comma_separated[2];
if ($item[$i] != null){
echo "<input type=\"text\" name=\"$quant[$i]\" size=\"1\" maxlength=\"2\" value=\"".$quant[$i]."\"> ";
echo $item[$i]; echo "@";
echo "$"; printf ("%01.2f", $price[$i]);
echo "<br/>";
}
}
?>
echo "<input type=\"text\" name=\"$quant[$i]\" size=\"1\" maxlength=\"2\" value=\"".$quant[$i]."\"> "; is changed to this echo "<input type=\"text\" name=\"quant\" size=\"1\" maxlength=\"2\" value=\"".$quant."\"> "; (i.e. it's "quant" as opposed to the array "quant") Thanks for your help so far Si! |
|
13 Blog Entries
|
2008-07-09
#6 |
||
|
Got it to work using the first post from Si. If anyone else is interested, here is what I did: Code:
for ($i = 0; $i < sizeof($line_separated); $i++){
// separate line by item
$comma_separated = explode(",",$line_separated[$i]);
$item[$i] = $comma_separated[0];
$price[$i] = $comma_separated[1];
$description[$i] = $comma_separated[2];
if ($item[$i] != null){
echo "<input type=\"text\" name=\"quant[]\" size=\"1\" maxlength=\"2\" value=\"".$quant[$i]."\"> ";
echo $item[$i]; echo "@";
echo "$"; printf ("%01.2f", $price[$i]);
echo "<br/>";
}
}
The part that helped was assigning name=quant[]. Then it worked. ![]() Thanks Si for your help! |
|
1 Blog Entries
13 Creative Assets
|
2008-07-09
#7 |
||
|
Hehe... I'm glad you got that working Andy, I have to admit it was confusing me a little.
|
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|




6 comments
| 469 views


13
13 Creative Assets

Linear Mode
For example...
<form ... > <input type="text" name="fruit[]" value="apple"/> <input type="text" name="fruit[]" value="banana"/> <input type="text" name="fruit[]" value="cherry"/> </form>