Updating multiple rows with an array using PHP with mySQLi
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 ?
Subject
Written By
Posted
Updating multiple rows with an array using PHP with mySQLi
September 15, 2009 07:38AM
September 20, 2009 03:54PM
September 21, 2009 04:29AM
September 21, 2009 09:14AM
September 22, 2009 04:47AM
September 22, 2009 08:48AM
September 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.