2013-07-19 43 views
0

在我的代码的第13行,我得到一个NULL $ NaN值。如果我用静态整数替换$ _POST ['amount'],则代码POST为正确的值。但试图添加一点功能,现在我无法获取数据通过?NULL单选按钮值

http://i40.tinypic.com/34gxauw.png

<div id="container"> 
<?php 
    require_once('stripe-php/lib/Stripe.php'); 
    $stripe = array(
    'secret_key' => 'sk_07C5ukIdqxyDGFqIKB8f7TXqGGyQt', 
    'publishable_key' => 'pk_07C58BHnzuFYQr9AUoZD6SCLiwANw' 
    ); 
    Stripe::setApiKey($stripe['secret_key']); 

    if ($_POST) { 
     $charge = Stripe_Charge::create(array(
      'card' => $_POST['stripeToken'], 
      'amount' => $_POST['amount'], 
      'currency' => 'usd' 
     )); 
     var_dump($_POST['amount']); 
     $quotes = array(
      "Thank you for your purchase!", 
      "Enjoy your experience with with us!" 
     ); 

     echo "<h1>Here's your quote!</h1>"; 
     echo "<h2>".$quotes[array_rand($quotes)]."</h2>"; 
    } 
    else { 
?> 

    <h2>TPC Holdings</h2> 
    <h3>Select your campaign package!!</h3> 

    <form> 
     <fieldset> 
      <legend>Select your package</legend> 
      <p> 
       <label>Select your package</label> 
       <input type = "radio" 
         name = "amount[]" 
         id = "sizeSmall" 
         value = "50" 
         checked = "checked" /> 
       <label for = "sizeSmall">$50.00</label> 

       <input type = "radio" 
         name = "amount[]" 
         id = "sizeMed" 
         value = "75" /> 
       <label for = "sizeMed">$75.00</label> 

       <input type = "radio" 
         name = "amount[]" 
         id = "sizeLarge" 
         value = "large" /> 
       <label for = "sizeLarge">$100.00</label> 
      </p> 
     </fieldset> 
    </form> 

    <form action="paybill.php" method="post"> 
     <script src="https://button.stripe.com/v1/button.js" 
      class="stripe-button" 
      data-key="<?php echo $stripe['publishable_key']; ?>" 
      data-amount="<?php echo $d_charge; ?>" 
      data-description="TPC purchase" 
      data-label="Buy"></script> 
    </form> 

<?php 
    } 
?> 

</div><!-- #container --> 
+0

'NAN'应该表示不是数字 - 我猜? – codingbiz

回答

0

不要amount fieldarray 用户select只有一个这些。

试试这个,

<p> 
    <label>Select your package</label> 
    <input type = "radio" 
     name = "amount" 
     id = "sizeSmall" 
     value = "50" 
     checked = "checked" /> 
    <label for = "sizeSmall">$50.00</label> 

    <input type = "radio" 
     name = "amount" 
     id = "sizeMed" 
     value = "75" /> 
    <label for = "sizeMed">$75.00</label> 

    <input type = "radio" 
     name = "amount" 
     id = "sizeLarge" 
     value = "large" /> 
    <label for = "sizeLarge">$100.00</label> 
</p> 
+0

,或者如果您确实将它命名为amount [size],然后将其作为'$ _POST [“amount”] [“size”];' – Orangepill

+0

同样问题与表单中的金额或金额[]相关联。 – brad

+0

@Orangepill我真的被困在这里。 – brad

0

您NAN问题是从value="large"到来。它应该是value="100"或任何您需要的值。我只能假设,值是如何处理的,你的处理程序是期待一个数字而不是一个字符串。