MySQL Forums
Forum List  »  PHP

Updating multiple rows with an array using PHP with mySQLi
Posted by: Craig Rushforth
Date: September 15, 2009 07:38AM

Please help with updating multiple rows with an array using PHP with mySQLi

I have managed to do this OK with an INSERT query, but am struggling with the syntax for an UPDATE query.

I would write single row UPDATE query like this...

if (array_key_exists('submit', $_POST)) {
// remove backslashes
// initialize flag
$OK = false;
// create database connection
$conn = dbConnect('admin');
// create SQL
$sql = 'UPDATE tblsize SET Display = ? WHERE SizeID = ?';

// initialize prepared statement
$stmt = $conn->stmt_init();
if ($stmt->prepare($sql)) {
// bind parameters and execute statment

$var1 = $_POST['display'];
$var2 = $_POST['ID'];

$stmt->bind_param('ii', $var1, $var2, $var3);/*s = string; i=integer; d=double; b=binary*/
$OK = $stmt->execute();
// redirect if successful or display error
if ($OK) {
header('Location: /xyz.php');
else {
echo $stmt->error;

Can someone please help me get my head around the syntax for updating several rows at once using an array ?

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.