//$update = $_POST;
//$quantity = $_POST;
//if($update){
//for($a=0;$a<$count;$a++){
mysql_query ("UPDATE productorder SET Product_quantity = '$quantity' WHERE id = '$id'");
THEY ONLY UPDATE THE LAST RECORD HOW I UPDATE THE MULITY RECORDS
//$update = $_POST;
//$quantity = $_POST;
//if($update){
//for($a=0;$a<$count;$a++){
mysql_query ("UPDATE productorder SET Product_quantity = '$quantity' WHERE id = '$id'");
THEY ONLY UPDATE THE LAST RECORD HOW I UPDATE THE MULITY RECORDS
Diagnosis and quick causes (references to the thread)
The behavior described by — three rows exist but only one ends up changed — is consistent with sending a single id/quantity pair to the server and repeating the same UPDATE. correctly flagged the page refresh inside the loop; an immediate redirect inside an iteration will abort further processing and can cause repeated submissions.
Practical fixes (form + server)
Example (safe, modern approach)
<?php
// assume $_POST['quantity'] is like ['3'=>2,'5'=>4]
$pdo = new PDO($dsn, $user, $pass, $opts);
$pdo->beginTransaction();
$stmt = $pdo->prepare('UPDATE productorder SET Product_quantity = :qty WHERE id = :id');
foreach ($_POST['quantity'] as $id => $qty) {
$stmt->execute([':qty' => (int)$qty, ':id' => (int)$id]);
}
$pdo->commit();
header('Location: shoping_cart12.php');
exit;
?> Bulk-update alternative
To reduce round-trips use a single query with CASE WHEN:
UPDATE productorder
SET Product_quantity = CASE id
WHEN 3 THEN 2
WHEN 5 THEN 4
ELSE Product_quantity END
WHERE id IN (3,5); Troubleshooting checklist and cautions
Jump to Post— Member #120589what's MULITY?
Jump to Post— Member #120589Sorry I still don't understand what you mean by 'mulity' - I Googled it and couldn't find it.
//$update = $_POST['update']; //$quantity = $_POST['quantity']; //if($update){ //for($a=0;$a<$count;$a++){ mysql_query ("UPDATE productorder SET Product_quantity = '$quantity' WHERE id = '$id'");This doesn't do anything does it? Your loop is commented …
Jump to Post— Member #120589show your complete code -it's impossible to see what you're doing from the bit you included. You don't include a loop so I assume it is impossible to update all unique 'id' records otherwise.
what's MULITY?
they only update the last row
they update only the last record
Sorry I still don't understand what you mean by 'mulity' - I Googled it and couldn't find it.
//$update = $_POST['update'];
//$quantity = $_POST['quantity'];
//if($update){
//for($a=0;$a<$count;$a++){
mysql_query ("UPDATE productorder SET Product_quantity = '$quantity' WHERE id = '$id'"); This doesn't do anything does it? Your loop is commented out and your $id seems to be static. Odd.
i have 3 row(records) in database table like
id order quantity
1 2232 1
2 2232 1
3 2232 1
they pick the last row(records)
id order quantity
3 2232 1
and update
how i update the i and 2 rows(records)
show your complete code -it's impossible to see what you're doing from the bit you included. You don't include a loop so I assume it is impossible to update all unique 'id' records otherwise.
<?php
// ********** update ************
mysql_connect("$hostname_boss", "$username_boss", "$password_boss")or die("cannot connect");
mysql_select_db("$database_boss")or die("cannot select DB");
$sql="SELECT * FROM productorder";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$update = $_POST['update'];
$quantity = $_POST['quantity'];
$id = $_POST['id'];
if($update){
for($a=0;$a<$count;$a++){
$insert="UPDATE productorder SET Product_quantity = '$quantity' WHERE id = '$id'";
$result1 = mysql_query($insert);
echo "<meta http-equiv=\"refresh\" content=\"0;URL=shoping_cart12.php\">";
}}
?>
first of all, you've included a meta refresh inside the loop. Don't do this. I'd use header() after the loop.
You're tables confuse me. I don't understand why you want to get the count of your orders and then loop over your insert statement that number of times.
UPDATE productorder SET Product_quantity = '$quantity' WHERE id = '$id' This will only ever update one record as it is unique (I assume the id is a primary key).
I'm thinking that you've misunderstood what you're trying to do.
$update = $_POST;
$quantity = $_POST;
$id = $_POST;
$insert1="UPDATE productorder SET Product_quantity = '$quantity' where product_id = '$id'";
$result1= mysql_query($insert1);
// if successful redirect to delete_multiple.php
if($result1){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=shoping_cart.php\">";
}
mysql_close();
no dear they only pick the last record and update it
2 problem they continuously refresh the page
how i can i time refresh the page
Sorry, I don't understand. Your code above should work. If you want to 'time refresh the page', do you mean pause for a while then refresh? If so:
<?php
header('Refresh: 5; URL=http://www.example.com');
?>
<p>You will be redirected in 5 seconds...</p> We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.