Trying to Update Multiple Records

I am trying to update multiple records when the customer checkouts and I keep getting this error:

Fatal error : Uncaught Error: Call to undefined method mysqli_stmt::get_result() in /home/oldmuleh/public_html/checkout.php:72 Stack trace: #0 {main} thrown in /home/oldmuleh/public_html/checkout.php on line 72

The first part of the code where the insert to orders works correctly. It is after that where it doesn’t work.

Any advice would be appreciated. Thanks

<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
if ($customers->getColumnVal("delivery_allowed") == 'N') {
$type = 'Pickup'; }
$delivery_date = htmlspecialchars($_POST['delivery_date']);
if ($customers->getColumnVal("delivery_allowed") == 'Y' or $customers->getColumnVal("delivery_allowed") == NULL) {
$type = htmlspecialchars($_POST['type']);}
$InsertQuery = new WA_MySQLi_Query($old_mule);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "orders";
$InsertQuery->bindColumn("customerID", "i", "".((isset($customerID))?$customerID:"")  ."", "WA_DEFAULT");
$InsertQuery->bindColumn("date_submitted", "s", "".((isset($today))?$today:"")  ."", "WA_DEFAULT");
$InsertQuery->bindColumn("type", "s", "".((isset($type))?$type:"")  ."", "WA_DEFAULT");
$InsertQuery->bindColumn("delivery_date", "t", "".((isset($delivery_date))?$delivery_date:"")  ."", "WA_DEFAULT");
$InsertQuery->saveInSession("orderID");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
$orderID = $_SESSION['orderID'];

    // Prepare statement to fetch dataIDs
    $stmt2 = $old_mule->prepare("SELECT cartID FROM cart WHERE customerID = ? and status='Added'");
    $stmt2->bind_param("i", $_SESSION['customerID']);
    $stmt2->execute();
    $result2 = $stmt2->get_result();
    $multiple_dataID = [];
    while ($row = $result2->fetch_assoc()) {
        $multiple_dataID[] = $row['cartID'];
    }
    $stmt2->close();

    // Update supplemental_info for each dataID
    $stmt3 = $old_mule->prepare("UPDATE data SET orderID = ? WHERE cartID = ?");
    $stmt3->bind_param("ii", $orderID, $thedataID);

    foreach ($multiple_dataID as $thedataID) {
        $stmt3->execute();
    }
    $stmt3->close();
    // Update supplemental_info for each dataID
    $stmt4 = $old_mule->prepare("UPDATE data SET status = 'Order Placed' WHERE cartID = ?");
    $stmt4->bind_param("i", $thedataID);

    foreach ($multiple_dataID as $thedataID) {
        $stmt4->execute();
    }
    $stmt4->close();


$fname = $customers->getColumnVal("fname");
$lname = $customers->getColumnVal("lname");
$email_address = 'XXX';
$message = "This email is to let you know $fname $name has placed a new online order for $type. Please login to the website to review the order details. Thank you. \r\n";
$message=wordwrap($message);
$to = $email_address;
$subject = "Action Needed: New Online Order for $fname $lname";
$headers = "From: noreply@XXX\r\n";
mail ($to, $subject, $message, $headers) or print "Error: Unable to send an email message to $email_address.";
header("Location: confirm_order.php?orderID=$orderID");
}
?>

The mysqli get_result() method is only available when php is complied for and actually uses the mysqlind driver. If you don’t manage your own web server, there’s no guarantee that any particular server installation will support this method. This results in non-portable code. You should avoid using the get_result() method whenever possible.

You can -

  1. Have your php installation recompiled with and configured to use the mysqlnd driver.
  2. Use the mysqli stmt bind_result() method - PHP: mysqli_stmt::bind_result - Manual
  3. Use whatever methods the WA (WebAssist) database class provides to execute a SELECT prepared query and fetch the result.
  4. Switch to the much simpler and more modern PDO extension.
2 Likes
Sponsor our Newsletter | Privacy Policy | Terms of Service