Cannot get variables to work

Hello,

I am brand new to PHP as of this semester of college. I have been breezing through a few labs and now I am stumped. Here is the proposed script to write:

Compose a script that creates a form that presents a customer a menu of choices for ice cream sundaes. Show vanilla, chocolate and peanut butter as ice cream flavors.

Display cherries, chocolate sprinkles, pineapple and walnuts as toppings. Allow neither the choice of chocolate sprinkles with chocolate ice cream, nor walnuts with peanut butter ice cream. Print a warning to the customer that those choices are not compatible.

Print to the monitor a final sundae build with flavor and toppings.

So, as of now, I have radio buttons set for all of the options. Two separate forms for both. My problem is getting a message to show up when certain combinations are selected. I cannot get the variables to work. I get an ‘undefined index’ when loading the page.

Here is what I have; I am trying an if/else statement when certain options are displayed.

<html>
<title>Lab4</title>

<body>

<form action = “final.php” method=“post”>
<center><h1>Crazy Ice Cream Lab 4</center></h1>
<center>
<div id=“icecream”>
<label>What kind of Ice Cream do you want?</label>
<br />
<input type=“radio” name=“icecream” value=“vanilla”> Vanilla <br />
<input type=“radio” name=“icecream” value=“chocolate”> Chocolate <br />
<input type=“radio” name=“icecream” value=“peanutbutter”> Peanut Butter <br />
</div>
</form>

&lt;form action = "final.php" method="post"&gt;
&lt;div id="toppings"&gt;
	&lt;br /&gt;
&lt;label&gt;what toppings would you like? &lt;/label&gt;
&lt;br /&gt;
&lt;input type="radio" name="toppings" value="cherries"&gt; Cherries &lt;br /&gt;
&lt;input type="radio" name="toppings" value="chocolatesprinkles"&gt; Chocolate Sprinkles &lt;br /&gt;
&lt;input type="radio" name="toppings" value="pineapple"&gt; Pineapple &lt;br /&gt;
&lt;input type="radio" name="toppings" value="walnuts"&gt; Walnuts &lt;br /&gt;

</div>

<div id=“buttons”>
<input type=“submit” value=“Submit”><br />
</div>
</form>
<?php

$icecream = $_POST[‘icecream’];
$toppings = $_POST[‘toppings’];

if ($icecream == “vanilla” and $toppings == “cherries”) {
echo “this is not a valid choice.”;
}
else
{
echo “”;
}

?>

</center>
</form>
</body>
</html>

Also, would it be possible to disable the submit button also with certain choices selected? I have tried looking up everything, nothing has been much help. Thanks for any insight you guys might have.

You get “index undefined” because when you first load the page there is nothing in $_POST. You may want to look up isset()

You have made 2 forms when you don’t really need to.

You have compounded the problem by making the first form without a submit button, so that data would never get sent.

Create a single <form></form> element, then in final.php do var_dump($_POST) to assess what is being sent to the form handler by the form.

You may also wish to change to && instead of “and”. So your IF statement might look like

if (isset($icecream) && $icecream == "vanilla" && isset($toppings) && $toppings == "cherries") {