2013-03-17 4 views
-1

나는 양식과 PHP를 가지고 있는데, 양식은 사용자에게 무엇을 사고 싶은지 물어보고 사용자가 선택하고 그것을 추가한다. 제출 버튼을 클릭하면 PHP vairables 제출 버튼 아래에 표시되지만 그 일을하는 방법을 몰라!양식을 제출하고 버튼을 제출 하시겠습니까?

<p><b>Billing Information</b></p> 
    <form action="" method="get"> 

     <p>Name: 
    <input type="text" name="firstname"> 
    <br> 
     <strong>Items:</strong></p> 
    </form> 
    <form id="form1" method="post" action=""> 
     <p> 
     <input type="checkbox" name="one" value= "2.39"/> 
     <label for="one">Four 100-watt light bulbs for $2.39</label> 
     <p> 
    <input type="checkbox" name="two" value= "4.29"/> 
    <label for="two">Eight 100-watt light bulbs for $4.29</label> 
    <p> 
     <input type="checkbox" name="three" value= "3.95"/> 
    <label for="three">Four 100-watt long-life light bulbs for $3.95</label> 
     </p> 
     <p> 
     <input type="checkbox" name="four" value= "7.49"/> 
    <label for="four">Eight 100-watt long-life light bulbs for $7.49</label> 
    </p> 
      <input name="battery" name = "battery" type="number" id="battery" size="1" maxlength="3" /> 
<label for="battery">Battery Packs Checkbox $10.42 each:</label> 
     </p> 
     <p><strong><b>Card Details</b>:</strong></p> 
<p> 
    <?php 
    if(isset($_POST['value'])) 
    { 
     $one = $_POST['one']; 
     $two = $_POST['two']; 
     $three = $_POST['three']; 
     $four = $_POST['four']; 
     $five = $_POST['battery']; 

    $total = $one + $two + $three + $four + $battery; 
    $interest = $total * 0.175; 
    echo "Total cost is " .$total; 
    } 
    ?> 
    </p> 
     <p> 
     <p> 
    <input name="Visa" type="radio" value= <?php $cardone = "Visa"; ?> 
    <p>Visa</p> 
    <p> 
      <input name="Mastercard" type="radio" value= <?php $cardtwo = "Mastercard"; ?> 
     <p>Mastercard</p> 
    <p> 
      <input name="American" type="radio" value=<?php $cardthree = "American Express"; ?> 
     <p> American Express </p> 
<p> 
    <?php 
    if(isset($_POST['value'])) 
    { 
     $cardone = $_POST['cardone']; 
     $cardtwo = $_POST['cardtwo']; 
     $cardthree = $_POST['cardthree']; 
    $total = $cardone + $cardtwo + $cardthree; 
    echo "You have chose to pay using a " .$total; 
    } 
    ?> 
<input type="Submit" name="SubmitForm" value="Submit"> 
<form action="Results.php" method="post"> 
<input name="Submit" type="button" /> 
</p> 
</form> 

죄송하지만이 문제가 정상적으로 해결되지는 않았지만 HTML은 좋지 않습니다. 도와주세요!

+0

새 페이지로 양식을 제출해야합니다. 동일한 페이지의 값에서'$ _POST '를 얻을 수 없습니다. –

+1

'$ _POST [ 'cardone']은 무엇입니까? 그 이름을 가진 폼 필드는 없으며, 이름은'Mastercard'입니다. 그리고 왜이 필드를 추가하고 있습니까? 숫자가 아닙니다. – Barmar

+0

하나의 일로, 당신은''당신의'

을 벗어납니다. –

답변

1

'value'양식 필드가 없으므로 양식을 닫지 않았습니다. 또한, 아래의 솔루션은 나를

<p><b>Billing Information</b></p> 
    <form action="" method="get"> 

     <p>Name: 
    <input type="text" name="firstname"> 
    <br> 
     <strong>Items:</strong></p> 
    </form> 
    <form id="form1" method="post" action=""> 
     <p> 
     <input type="checkbox" name="one" value= "2.39"/> 
     <label for="one">Four 100-watt light bulbs for $2.39</label> 
     <p> 
    <input type="checkbox" name="two" value= "4.29"/> 
    <label for="two">Eight 100-watt light bulbs for $4.29</label> 
    <p> 
     <input type="checkbox" name="three" value= "3.95"/> 
    <label for="three">Four 100-watt long-life light bulbs for $3.95</label> 
     </p> 
     <p> 
     <input type="checkbox" name="four" value= "7.49"/> 
    <label for="four">Eight 100-watt long-life light bulbs for $7.49</label> 
    </p> 


      <input name="battery" name = "battery" type="number" id="battery" size="1" maxlength="3" /> 
<label for="battery">Battery Packs Checkbox $10.42 each:</label> 

    <input type ="submit" name="value" /> 

</form> 
     <p><strong><b>Card Details</b>:</strong></p> 



<p> 

    <?php 
    if(isset($_POST['value'])) 
    { 
     $one = $_POST['one']; 
     $two = $_POST['two']; 
     $three = $_POST['three']; 
     $four = $_POST['four']; 
     $five = $_POST['battery']; 

    $total = $one + $two + $three + $four + $five; 

    $interest = $total * 0.175; 
    echo "Total cost is " .$total; 
    } 


    ?> 

    </p> 

편집 작동에는 $ 배터리 없다 : 당신은 별도의 형태로 '이름'을 필요로하는 경우 잘 모릅니다. 나는 그것에 대해 틀릴 수도 있습니다. 편집 : 귀하의 질문에 귀하의 코드가 꽤 바뀌 었습니다. 이 답변이 더 이상 적용될 수 있는지 확실하지 않습니다.

관련 문제