|
Posted by Ryan on 01/03/07 22:53
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>";
}
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, am I, passing the $name, $price, and $qty variables to the
testprocess.php page? Can I even pass php variables to another script
in such a manner? I guess I'm also not quite sure as to how to call
them either. Thanks.
Rik wrote:
> Ryan wrote:
>> The only problem with that, is I'm trying to stay within the
>> guidelines of where I am in the book. It appears I'm having trouble
>> just sending data in an array from one site to another. I take it
>> using the html 'sumbit' won't work in a php script?
>
> Well, it works wonderfully thank you very much :-)
>
>> I tried using
>> regular arrays to store price, names, and the quantity the user
>> inputs, but when I try to echo any of that into the process.php
>> script, nothing displays.
>
> Hard to say what's wrong without that code, but if the book's that bad you
> probaly want to check out register_globals and a lot can become clear. If
> not, post the snippet of your receiving code.
>
>> It's not a huge ordeal, I just though I'd
>> try update my pages as I go along with the book. Thanks though!
>
> Well, normally one would have some kind of 'id' for the different commics.
> If you'd name you input fields 'quantity[{$id}] for instance, you'd have a
> perfectly servicable array on the receiving end when posting in
> $_POST['quantity']. With thing like array_filter() and the like you can
> work on the whole array quite fast, and is often a more efficient and
> faster solution then going OO.
[Back to original message]
|