echo "<form action='' method=\"post\">";
echo "<table border='1'>
    <tr class='' >   
    <th> P.Name </th>
    <th> P.Size </th>
    <th> P.Quantity </th>
    <th> P.Price </th>
    <th> P.Delete </th>
    $query ="SELECT * FROM `order_detail` WHERE `orderID` = $viewID ";

      echo "<tr>";

      echo "<td> <input type=\"text\"  name=product_name value=\"$row[prodName]\"> </td>";
      echo "<td> <input type=\"text\"  name=product_size value=$row[prodSize]> </td>";
      echo "<td> <input type=\"text\"  name=product_qty value=$row[prodQty]>  </td>";
      echo "<td> <input type=\"text\"  name=product_price value=$row[prodPrice]></td>";
      $query_sting = "Id={$row['ID']}&veiw=$viewID";
      $delete_page = "order_delete.php?". $query_sting;
      echo "<td><a href='$delete_page' onclick=\"return confirm('Are you sure?');\"><img src='images/DELETE.png'></a></td>";
      echo "</tr>";
    echo "</table>";
    echo "</form>";
        $sql ="UPDATE order_detail SET ";
      $sql .="prodName = '$product_name', ";
      $sql .="prodSize = '$size', ";
      $sql .="prodQty  = '$product_qty',";
      $sql .="prodPrice = '$product_amount' ";
      $sql .="WHERE `ID` ='$Id' ";
      $result = mysqli_query($connection,$sql);}


thnx in advance
want to update mutiple record
this code is updated the last record only

3 Years
Discussion Span
Last Post by cereal

In order to perform multiple updates you have to submit the fields of the form as array groups, for example:

<form action="" method="post">

            <!-- group 0 -->
            <td><input type="text" readonly name="product[0][id]" value="23" /></td>
            <td><input type="text" name="product[0][name]" /></td>
            <td><input type="text" name="product[0][size]" /></td>
            <td><input type="text" name="product[0][qty]" /></td>
            <td><input type="text" name="product[0][price]" /></td>
            <!-- group 1 -->
            <td><input type="text" readonly name="product[1][id]" value="72" /></td>
            <td><input type="text" name="product[1][name]" /></td>
            <td><input type="text" name="product[1][size]" /></td>
            <td><input type="text" name="product[1][qty]" /></td>
            <td><input type="text" name="product[1][price]" /></td>

    <input type="submit" name="button" value="update" />

When you print the $_POST array you get:

    [product] => Array
            [0] => Array
                    [id] => 23
                    [name] => Apples
                    [size] => 1
                    [qty] => 10
                    [price] => 6

            [1] => Array
                    [id] => 72
                    [name] => Oranges
                    [size] => 2
                    [qty] => 17
                    [price] => 8.90


    [button] => update

At this point you can loop $_POST['product'] to update each product separatedly:

foreach($_POST['product'] as $product)
    echo $product['id'] . $product['name'] . '... and so on';

Best would be to use prepared statements so you can create the update query and then just loop the execution with the parameters.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.