0

Given this code snippet, I know that if the user selects 25c the value 25 will be sent to the php script; however, I am having issues trying to figure out how to setup the data on the php script so that I could manipulate it.

   <label><b>Quarters:</b></label>
    <select name="quarters" >
    <option value="25">25c</option>
    <option value="50">50c</option>
    <option value="75">75c</option>
    <option value="100">$1.00</option>
    </select>

Currently all I have is this on the php script:

// A money array.
    $money = array("Nickels" => "$value", "Dimes" => "$value", "Quarters" =>"$value");

If the user clicks on the option for for Quarters and selects 50c the value will be 50 on the HTML side, but how do I get that 50 onto the php side, since this value is depended on what the user selects, in some cases the user can select 75c, and the value 75 is transferred to the php script.

Can't use a variable it only holds one value, so I am thinking multi-dimensional array to hold all the possible values that a user can select from 25c value 25 to $1.00 value 100.

User can only select one value at a time,not a combination of values.

3 Answers 3

1

your <select> have to be in form tag depending the if the method attribute is set to GET or POST the variable would be available in $_GET['quarters'] ($_GET)or $_POST['quarters'] ($_POST).

I advice to set your method to POST it's usually the best way to submit forms

$money = array("Nickels" => $_POST["nickels"], "Dimes" => $_POST["dimes"], "Quarters" =>$_POST["quarters"]);

there is also a super global called $_REQUEST which will handle POST/GET/COOKIE variables(anything from the user). I advice you to use $_REQUEST carefully because it can create problems.

Sign up to request clarification or add additional context in comments.

1 Comment

$_REQUEST contains both $_POST and $_GET, but also $_COOKIE. I'd go for one of $_POST or $_GET.
1

Use $_REQUEST['quarters'] It will return either: 25,50,75, or 100 from the form.

Comments

0

One thing you could do, is instead of using $value for your Nickels, Dimes, and Quarters inputs, use the $_REQUEST array.

For example, your example array would be:

// A money array.
    $money = array("Nickels" => $_REQUEST["nickels"], "Dimes" => $_REQUEST["dimes"], "Quarters" =>$_REQUEST["quarters"]);

Assuming your naming convention for Nickels/Dimes was consistent with your Quarters example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.