DuveoDit
DuveoDit

Reputation: 1

Running multiple if statements at once PHP

I'm trying to print the quantity chosen from a table to another page. I have a series of if statements for this to show if a quantity has been inputted and if it has then it will display the quantity and the item.

The problem is that it is only running the first if statement and ignoring the rest of them. If anyone knows how I could run them all it would be a great help!

<?php

  if(!empty($_POST['qtybang']))
  {
    echo $qtybang.' Bang Bang Chicken<br>';
  }

  if(!empty($_POST['$qtyFlatbread']))
  {
    echo $qtyFlatbread.' Flatbread<br>';
  }

  if(!empty($_POST['$qtyMexican']))
  {
  echo $qtyMexican.' Mexican Bean Stew<br>';
  }

  if(!empty($_POST['$qtyrice']))
  {
  echo $qtyrice.' Rice Bowl<br>';
  }

  if(!empty($_POST['$qtySandwiche']))
  {
  echo $qtySandwiche.' sandwiches<br>';
  }


  if(!empty($_POST['$qtyCapachino']))
  {
  echo $qtyCapachino.' Capachino<br>';
  }


  if(!empty($_POST['$qtyAmericano']))
  {      
  echo $qtyAmericano.' Americano<br>';
  }


  if(!empty($_POST['$qtyExpresso']))
  {
  echo $qtyExpresso.' Expresso<br>';
  }?>

Order Table

Output

Upvotes: 0

Views: 210

Answers (1)

vv01f
vv01f

Reputation: 372

The if statements are actually processed but simply the checked vars are empty, thats why you have no output. It was because the $ in the $_POST list are placed wrong on all instances except the first condition.

    <?php
     $_POST['qtybang'] = 'something';
     $qtybang = $_POST['qtybang'];
     $_POST['$qtyFlatbread'] = 'something';
     $qtyFlatbread = $_POST['$qtyFlatbread'];

     if(!empty($_POST['qtybang']))
     {
       echo $qtybang.' Bang Bang Chicken<br>'."\n";
     }

     if(!empty($_POST['$qtyFlatbread']))
     {
       echo $qtyFlatbread.' Flatbread<br>'."\n";
     }

     if(!empty($_POST['$qtyMexican']))
     {
       echo $qtyMexican.' Mexican Bean Stew<br>'."\n";
     }

     if(!empty($_POST['$qtyrice']))
     {
       echo $qtyrice.' Rice Bowl<br>'."\n";
     }

     if(!empty($_POST['$qtySandwiche']))
     {
       echo $qtySandwiche.' sandwiches<br>'."\n";
     }


     if(!empty($_POST['$qtyCapachino']))
     {
      echo $qtyCapachino.' Capachino<br>'."\n";
     }


     if(!empty($_POST['$qtyAmericano']))
     {      
       echo $qtyAmericano.' Americano<br>'."\n";
     }


     if(!empty($_POST['$qtyExpresso']))
     {
       echo $qtyExpresso.' Expresso<br>'."\n";
     }
?>

Upvotes: 1

Related Questions