Help with Looping PHP Forms

Discussion in 'PHP' started by *Brandon, Apr 1, 2010.

  1. #1
    I'm building a pizza shop for a school assignment and I am stuck with trying to get the information from an array containing the toppings

    Here's the code from the form. (this form is looped for several pizzas)
    <li><input type="checkbox" name="toppings1[]" value="pepperoni"> Pepperoni</li>
    PHP:
    and here is what I started with proccessing the order but cant get the toppings to come out of this array properly.
    
    $toppings1 = $_POST['toppings1'];
    ///This loop will output the topping selected for all the pizzas.
    foreach($toppings1 as $key => $value){
    echo "$toppings1 $key $value <br>";
    }
    
    //Some reason this code wont work to call a topping from the array
    echo $toppings1[0]<br>";
    
    PHP:

     
    *Brandon, Apr 1, 2010 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Small fix:
    echo $toppings1[0] . "<br />";
    PHP:
    Other then that it should work fine.
     
    Alex Roxon, Apr 2, 2010 IP