Ryan Williams Ryan Williams - 2 months ago 12
HTML Question

2 Submits 1 Works same code?

So I have 2 submit buttons no matter what even if i remove all the code from broken button I get a 403 erorr forbidden but the second submit button works...

Here is my html/php code for buttons:

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


Code for buttons:

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();
}


Only difference is wherever btc is its pp for the broken button.

Answer

Only <input type="submit" class="btn btn-info" value="Pay with Bitcoin" name="btc"> will work because in your php code, you are only posting this <input type="submit" class="btn btn-info" value="Pay with Bitcoin" name="btc">

To achieve your goal,

Use same name for both button but with a different value for each.

<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">

Then in your php file:

<?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
    }
  }

?>