MySQL Forums :: PHP :: Updating multiple rows with an array using PHP with mySQLi


Advanced Search

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...

<?php
if (array_key_exists('submit', $_POST)) {
include('../includes/conn_mysqli.inc.php');
include('../includes/corefuncs.php');
// remove backslashes
nukeMagicQuotes();
// 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');
exit;
}
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


Subject Written By Posted
Updating multiple rows with an array using PHP with mySQLi Craig Rushforth 09/15/2009 07:38AM
Re: Updating multiple rows with an array using PHP with mySQLi Rick James 09/20/2009 03:54PM
Re: Updating multiple rows with an array using PHP with mySQLi Craig Rushforth 09/21/2009 04:29AM
Re: Updating multiple rows with an array using PHP with mySQLi Rick James 09/21/2009 09:14AM
Re: Updating multiple rows with an array using PHP with mySQLi Craig Rushforth 09/22/2009 04:47AM
Re: Updating multiple rows with an array using PHP with mySQLi Rick James 09/22/2009 08:48AM
Re: Updating multiple rows with an array using PHP with mySQLi Craig Rushforth 09/23/2009 09:45AM


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.