You are here: Re: Getting quantity input for each product in a product/price associative array « PHP Language « IT news, forums, messages
Re: Getting quantity input for each product in a product/price associative array

Posted by Richard Schneidt on 01/03/07 23:36

Ryan schrieb:
> 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>";

you only pass the value from the input tag you name $qty[$i], I guess
that is not what you want.

> }
> 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:

Not sure exactly what you are doing, but if the code below is the code
you use to get the values in testprocess.php, then I would expect, that
you only have a value in $adress.
>
> $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

You can pass everything if done right:-)
If you put the content of these vars in input fields or hidden input
fields you can pass them, but it is a lot easier to put them in a
session and just access the session on each page.

> in such a manner? I guess I'm also not quite sure as to how to call
> them either. Thanks.
>
>

I think you haven't understood the concept. Here comes a short explanation.


To post some values to another php page you need to setup the submission
form:

<form id="whatever" name="somename" method="post" action="testprocess.php">
<input type="text" name="Surname" />
<input type="submit" name="Submit" value="Submit" />
</form>


Now as soon as you push the submit button if will send the form data to
the page you specified in action=""

Now on testprocess.php you can get this data, by quering for the field
names, in the above example you have once field called "Surname". You
get it with:

$surname = $_POST['Surname'];

So you can only fetch values from form elements, like <input,<select ..
Any text inside the form is not submitted, for example:

<td>$name[$i]</td> as you wrote in your example is no form element. So
you would have to put the value in a form element like a input box, then
it will be transfered on submission. But it is not practical to do that
if you have a bunch of values form an array unless you want to show the
user a list of values which he can select and then submit it.


So my advice don't think about complicated uses of posting content via
forms to another page, just try out how basic submission of simple input
fields work. Later on when you get to sessions you will findout that it
is much easier to store all the data on serverside inside a session that
belongs to a unique user.

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация