<?php
// Turn on error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Set your connection details
$hostname = 'localhost';
$username = 'yourUserName';
$password = 'yourPassword';
$database = "yourDatabase";
try {
// Connect to your database
$dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// Prepare a parameterised UPDATE statement and bind the parameters to variables
$stmt = $dbh->prepare("UPDATE utmp_orders SET lbl_qty = :qty, lbl_prc = :price WHERE t_ordid = :id");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':qty', $qty);
// Intialise a record tracker
$recordsUpdated = 0;
// Loop through the POSTed data
foreach ($_POST['records'] as $record) {
//Execute the prepared UPDATE statement
$stmt->execute($record);
// Update the record tracker
$recordsUpdated++;
}
// Output a summary to the user
printf("Records Updated: %d", $recordsUpdated);
} catch(PDOException $pdoEx) {
// We have a problem
die($pdoEx->getMessage());
}