|
Posted by Rik on 01/03/07 23:22
Ryan wrote:
Please don't toppost.
> Maybe I'm doing this wrong. So my main page, test.php, has three
> arrays; one for price ($price), one for the names of products ($name)
> and one for the quantity the user must input($qty). There's also an
> input field for the users address. For the address field, I used
> solely HTML: <input type="text" name="address" size="20"
> maxlength="30">
> For the names, prices, and quantity fields, however, I use a for loop
> to scroll through the names, prices, and create an input field for
> qty:
>
> for($i = 0; $i < 3; $i++)
> {
> echo "<tr><td>$name[$i]</td><td>$price[$i]</td><td
> align='center'><input type='text' name=$qty[$i] size='3'
> maxlength='3'></td></tr>";
> }
The problem here is this:
<input type='text' name=$qty[$i]
------------------------^^^^
Change it to:
<input type='text' name="qty[$i]" value="{$qty[$i]}"
> Now, for some reason, only the address data sends to the next script
> (testprocess.php). Here's what I'm using to call the data for all the
> variables:
>
> $name = $_POST[$name];
> $price = $_POST[$price];
> $qty = $_POST[$qty];
> $address = $_POST['address'];
I wonder, are $name,$price and $qty set variables, and is so, are they
scalars referring to the variable in the POST array?
Add this on top of every code to get hints:
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT);
With the above change, the array of quantities should be in $_POST['qty'].
When you're not sure wether the $_POST array (or any variable for that
matter) contains the right data, use var_dump($_POST); (or any other
variable name offcourse) to check what kind of data it holds.
> I wonder, am I, passing the $name, $price, and $qty variables to the
> testprocess.php page?
No, only variables put explicitly in an input (/textarea/select) are
posted, currently the only variables you send is the $qty array step for
step. And you don't send it as a value at the moment, but as the name,
which I would not recommend :-). Only scalars (string, integers,..) can be
posted, no arrays or objects. (Unless you cast them to a string with for
instance serialize, but that's not necesarry for your code.
--
Rik Wasmus
Navigation:
[Reply to this message]
|