Jump to content

arrays foreach loops and checkboxes


panthers_uni

Recommended Posts

Hey forum,

 

I am a new php user and am having some issues (probably pretty basic to the likes of more experienced users), I am trying to make a script that has 4 checkboxes and a submit button, the values of the checkboxes should be passed through the array using a foreach loop, I got the basic template setup but when trying to pass the array I ran into a few problems.

 

If anyone would take a peek at my code and point me in the right direction it would be much appreciated.

 

Thanks forum.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Here is a text version of the code

 

<html>
<title>Toppings</title>
<body>

<p>What do you want on your pizza?</p>

<form action="ProcessToppings.php" method="post">

<?php
//define varialbes

$Output_form = false;
$submit = $_POST['submit'];

if(isset($submit))	
{
if(empty($toppings))  

{
		echo '<b>You forgot to choose a topping(s).</b>';
		echo '<br>';
		echo '<br>';
		$Output_form = true;	
	}

else
	{

		$toppings=array("0", "1", "2", "3");

foreach ($toppings ['toppings'] as $order)
  {
  echo  'Your pizza will have these topping: ' . $toppings . '<br/>';
  $Output_form = false;
  }
	}
}
?>

<input type="checkbox" name="toppings[0]" value="pepperoni" />Pepperoni<br />
<input type="checkbox" name="toppings[1]" value="sausage" />Sausage<br />
<input type="checkbox" name="toppings[2]" value="mushrooms" />Mushrooms<br />
<input type="checkbox" name="toppings[3]" value="olives" />Olives
<p>
<input type="submit" value="Place Order" name="submit" /></p>

</form>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.