Thursday, 28 March 2019

SQL not updating even after link (using PHP)

I will explain all the connections first:

"orders.php"

I have a table in this file where I outputted the info using a foreach loop, Id like to just focus on the "SCHEDULED?" column however.

require_once('orders-claimed.vc.php');

<tr align="center" id="<?php echo $rowOrder['orderid']; ?>">
<td>
  <?php
  foreach($lstOrder as $rowOrder) {
  //access database table "orders" (snippet)


    if ($rowOrder['scheduled'] == 'YES') {
   ?>
   <button type="button" class="btn-success yes-button" name="yes" id="<?php echo $rowOrder['orderid'] ;?>">YES</button>
  <?php
} else if ($rowOrder['scheduled'] == 'NO') {
    ?>
   <button type="button" class="btn-danger no-button" name="no" id="<?php echo $rowOrder['orderid'] ;?>">NO</button>
  <?php
    }
   ?>
</td> 
</tr>

1

"orders-claimed.vc.php"

this file is where SQL gets connected to the table, below is a snipped of the "NO" button (name="no" in orders.php).

  require_once($routePath . "_mc/Order.mc.php");
  $mcOrder = new Order_MC();

        if (isset($_POST['no'])) {
    $mcOrder->Scheduled_Yes($db, $orderid);
  }

"Order.mc.php"

finally here is where the SQL code is located.

<?php
public function Scheduled_Yes($db, $orderid, $scheduled) {
 $stmt = $db->prepare(
   " UPDATE order
     SET scheduled = 'YES'
     WHERE orderid = :orderid "
 );

 $stmt->bindValue(':orderid', $orderid, PDO::PARAM_INT);
 $stmt->bindValue(':scheduled', $scheduled, PDO::PARAM_INT);
 $stmt->execute();
 $rowAffected = $stmt->rowCount();

 return $rowAffected;
}

enter image description here

  • Supposed to be "NO" will change to "YES" in the database, on paper everything seems to be connected but the SQL does not trigger when I click the button. Am I missing something or did I do the connections to the SQL and PHP wrong?

Any help would be appreciated.

UPDATE:

CHANGES:

"orders-claimed.vc.php"

$mcOrder->Scheduled_Yes($db, $orderid, $scheduled);

"Orders.mc.php"

WHERE orderid = :orderid AND scheduled = :scheduled "

both still gets no effect even when the parameters and WHERE is called



from SQL not updating even after link (using PHP)

No comments:

Post a Comment