开发者

Help with php script addition and % (also a compile error)

I am trying to set up a php script that takes the input from a web 开发者_如何学Goform in this case a couple of drop down boxs, (extras and Trainers) and totals them up with a 20% tax on top of the total. I am unsure how to do the total, and also the 20% take also additionally I get error on line 80 which is the very last closing tag (i am very new to php)

    <?php


    $extras = array(
          'Laces' => 5,
          'Shoe Polish' => 10,
          'In-souls' => 15
    );

    $trainers = array(
          'Lacoste' => 50,
          'K-Swiss' => 45,
          'Puma' => 59,
          'Converse' => 65
    );


        {
      $firstname = $_POST['firstname'];
      echo "Firstname $firstname <br />\n";
     }

     {
      $lastname = $_POST['lastname'];
      echo "Lastname $lastname <br />\n";
     }

      {
      $add1 = $_POST['add1'];
      echo "$add1 <br />\n";
     }

     {
      $add2 = $_POST['add2'];
      echo "$add2 <br />\n";
     }
      {
      $postcode = $_POST['postcode'];
      echo "$postcode <br />\n";
      }
      {
      $email = $_POST['email'];
      echo "Contact Email Address $email <br />\n";
      }
      {
      $telephone = $_POST['telephone'];
      echo "Contact Telephone Number $telephone <br />\n";
      }
      {
      $contact = $_POST['contact'];
      echo "You would like to be contacted by $contact <br />\n";
      }

      {
      $trainers = $_POST['trainers'];
      echo "The trainers you would like are $trainers <br />\n";
      }

      {
      $extras = $_POST['extras'];
      echo "The extras you would like are $extras <br />\n";
      }

     $extraCost = 0;
     $trainerCost= 0;
     $totalCost= 0;


    $extra = $_POST['extras'];

    if (in_array($extra, $extras)) {
        $runningCost = $extras[$extra];
        echo "The cost of your extras are $extraCost<br />\n";

$extra = $_POST['trainers'];

    if (in_array($trainer, $trainers)) {
        $runningCost = $trainers[$trainer];
        echo "The cost of your Trainers are $trainerCost<br />\n";
    }

    ?>

Thank you very mych!


   $extraValues = array(
      'Laces' => 5,
      'Shoe Polish' => 10,
      'In-souls' => 15
   );

   $trainerValues = array(
      'Lacoste' => 50,
      'K-Swiss' => 45,
      'Puma' => 59,
      'Converse' => 65
   );

   if(isset($_POST['firstname'])){
      $firstname = $_POST['firstname'];
      echo "Firstname $firstname <br />\n";
   }

   if(isset($_POST['lastname'])){
    $lastname = $_POST['lastname'];
    echo "Lastname $lastname <br />\n";
   }

  if(isset($_POST['add1'])){
    $add1 = $_POST['add1'];
    echo "$add1 <br />\n";
  }

 if(isset($_POST['add2'])){
  $add2 = $_POST['add2'];
  echo "$add2 <br />\n";
 }

  if(isset($_POST['postcode'])){
    $postcode = $_POST['postcode'];
    echo "$postcode <br />\n";
  }

  if(isset($_POST['email'])){
    $email = $_POST['email'];
    echo "Contact Email Address $email <br />\n";
  }

  if(isset($_POST['telephone'])){
  $telephone = $_POST['telephone'];
  echo "Contact Telephone Number $telephone <br />\n";
  }

  if(isset($_POST['contact'])){
  $contact = $_POST['contact'];
  echo "You would like to be contacted by $contact <br />\n";
  }

  if(isset($_POST['trainers'])){
  $trainers = $_POST['trainers'];
  echo "The trainers you would like are $trainers <br />\n";
  }

  if(isset($_POST['extras'])){
  $extras = $_POST['extras'];
  echo "The extras you would like are $extras <br />\n";
  }



   $extraCost = 0;
   $trainerCost= 0;
   $totalCost= 0;

    $extra = $_POST['extras'];

    if (array_key_exists($extra, $extraValues)) {
         $extraCost = (float) $extraValues[$extra]; 
        echo "The cost of your extras are $extraCost<br />\n";
    } // this brace was missing and causing your error

    // if this is the name then use array_key_exists in the if statement below
    $trainer = $_POST['trainers'];

    if (array_key_exists($trainer, $trainerValues)) { 
        $trainerCost = (float) $trainerValues[$trainer]; 
        echo "The cost of your Trainers are $trainerCost<br />\n";
    }

  // add 20%, and round to 2 decimal places...
  $totalCost = round(($extraCost+$trainerCost+$totalCost)*1.2, 2); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜