2提交1作品相同的代码?

时间:2016-10-05 03:59:03

标签: php html

所以我有2个提交按钮,即使我从破坏的按钮中删除所有代码,我得到403 erorr禁止但第二个提交按钮工作...

这是我的按钮的html / php代码:

<form action="buy.php?id=<?php echo $id; ?>" method="POST">
<input type="email" class="form-control" name="email" placeholder="Email" required>
<br>
<p></p>
<?php if($row['pp'] == 1){
echo '
<input type="submit" class="btn btn-primary" value="Pay with Paypal" name="pp">';
} ?>
<p></p>
<?php if($row['btc'] == 1){
echo '
<input type="submit" class="btn btn-info" value="Pay with Bitcoin" name="btc">';
} ?></form>

按钮代码:

if(isset($_POST['btc'])){
    $email = htmlentities($_POST['email'], ENT_QUOTES);
    $stmt = $db->prepare("INSERT INTO invoices (itemid, username, email, price, status, type) VALUES (:itemid, :username, :email, :price, :status, :type)");
    $stmt->execute(array(':itemid' => $id, ':username' => $row['username'], ':email' => $email, ':price' => $row['price'], ':status' => "awaiting", ':type' => "btc"));
    $id = $db->lastInsertId();
    $stmt = $db->prepare("SELECT * FROM invoices WHERE id = :id");
    $stmt->execute(array(':id' => $id));
    $row2 = $stmt->fetch();
}

唯一区别在于btc是破坏按钮的pp。

1 个答案:

答案 0 :(得分:2)

只有<input type="submit" class="btn btn-info" value="Pay with Bitcoin" name="btc">才有效,因为在您的PHP代码中,您只发布此<input type="submit" class="btn btn-info" value="Pay with Bitcoin" name="btc">

为了实现目标,

对两个按钮使用相同的名称,但每个按钮的值都不同。

<input type="submit" class="btn btn-primary" value="Pay with Paypal" name="btnPay">
<input type="submit" class="btn btn-info" value="Pay with Bitcoin" name="btnPay">

然后在你的php文件中:

<?php

  if(isset($_POST['btnPay'])){
    if($_POST['btnPay'] == "Pay with Paypal"){
      //code for paypal payment
    }
    else if($_POST['btnPay'] == "Pay with Bitcoin"){
      //code for bitcoin payment
    }
  }

?>