2011-03-28 3 views
0

이 경우 웹 양식의 입력을받는 PHP 스크립트를 설정하려고합니다. 드롭 다운 상자, (엑스트라 및 트레이너) 및 합계 최대 20 % 세금이 부과됩니다. 나는 총을 수행하는 방법 확실하지 오전, 또한도 20 % 걸릴 또한 나는 맨 마지막 닫는 태그 (내가 PHP는 매우 새로운 오전)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"; 
    } 

    ?> 

당신에게 매우 mych 감사하다 라인 (80)에 오류가!

+1

글타래의 구문 분석 오류는 ifra 문에 닫는'}'이 없기 때문에 발생합니다. – prodigitalson

답변

2
$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

이 코드는 어디에 두어야합니까? – Chris

+0

당신의 코드에있는 것과 같은 자리에 ... 나는 당신의 의도를 잘못 읽었 기 때문에 일부 오타들과 몇몇 변수들에 soem 변경을했음을 노트하십시오 ... – prodigitalson

+1

+1, but + 20 % = * 1.20 not * 1.02. –