Martin Smith
Martin Smith

Reputation: 61

Php isset not working after button click

For some reason when I click the cancel button it should run through the Cancel isset mysql query but it doesn't. It only passes through the mysql query when I make it a $_GET instead of a $_POST. Not entirely sure whats happening.

if(isset($_POST["Cancel"])) {
$sCancel = $dbh->prepare("                             
    UPDATE MaterialOrders                              
    SET `cancelledByUid` = :uid,                       
        `cancelled` = 'true'                           
    WHERE `idMaterialOrders` = :idMaterialOrders       
");                                                    
$sCancel->bindValue(":uid", $_SESSION["uid"]);         
$sCancel->bindValue(":idMaterialOrders", $_GET["oid"]);
if ($sCancel->execute()) {                             
    $sCancel->closeCursor();                           
}                                                      

}

<a href="includes/orderItems.php?Cancel=true&oid=<?php print $_GET['oid']; ?>" class="supplierMaterial" target="_blank"> 
<input type="button" value="Cancel Order" name="Cancel" id="Cancel">                                                 

Upvotes: 0

Views: 775

Answers (2)

Narayan Bhandari
Narayan Bhandari

Reputation: 426

Since you are implementing when a link is clicked, you could only use $_GET because to use it as $_POST, form must be submitted in post method. Please try this,

<a href="includes/orderItems.php?Cancel=true&oid=<?php print $_GET['oid']; ?>" class="supplierMaterial" target="_blank"> 
    <input type="button" value="Cancel Order" name="Cancel" id="Cancel">
</a>

Upvotes: 1

user4628565
user4628565

Reputation:

try this,

<form method="post" action="includes/orderItems.php">
<a href="?Cancel=true&oid=<?php print $_GET['oid']; ?>" class="supplierMaterial" target="_blank"> 
<input type="button" value="Cancel Order" name="Cancel" id="Cancel">
<input type="submit" value="submit" name="submit" id="submit">
</form>

Upvotes: 0

Related Questions