Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Obodo

  1. hello all i am building a shopping system, but i am stuck. i want to update items in the database but it is affecting only the last row. thanks for the help <input type="hidden" class="form-control" name="prod_id" value="'.$values["product_ids"].'" /> <td><input type="text" class="form-control" readonly name="prod_name" value="'.$values["product_name"].'" /></td> <td><input type="text" class="form-control" readonly name="prod_type" value="'.$values["product_type"].'" /></td> <td><input type="text" class="form-control" readonly name="prod_size" value="'.$values["product_size"].'" /></td> <td><input type="text" class="form-control" readonly name="prod_qty" value="'.$values["product_quantity"].'" /></td> <td><input type="text" class="form-control" readonly name="prod_price" value="'.$values["product_price"].'" /></td> <td><input type="text" class="form-control" readonly name="total_price" value="'.number_format($values["product_quantity"] * $values["product_price"], 2).'" /></td> if(isset($_POST['enter'])) { require_once 'database_connection.php'; $prod_name = $_POST['prod_name']; $prod_id = $_POST['prod_id']; $prod_type = $_POST['prod_type']; $prod_size = $_POST['prod_size']; $prod_qty = $_POST['prod_qty']; $prod_price = $_POST['prod_price']; $total_price = $_POST['total_price']; $trans_ref = mt_rand(10000, 99999); $sql = "INSERT INTO test_sales ( trans_ref, prod_id, prod_name, prod_type, prod_size, prod_qty, prod_price, total_price, trans_date ) VALUES ( :trans_ref, :prod_id, :prod_name, :prod_type, :prod_size, :prod_qty, :prod_price, :total_price, NOW() )"; $stmt = $connect->prepare($sql); $stmt->execute(array( ':trans_ref' => $trans_ref, ':prod_id' => $prod_id, ':prod_name' => $prod_name, ':prod_type' => $prod_type, ':prod_size' => $prod_size, ':prod_qty' => $prod_qty, ':prod_price' => $prod_price, ':total_price' => $total_price )); $num_rows = $stmt->rowCount(); if($num_rows){ $sql = " UPDATE products SET qty = qty - '$prod_qty' WHERE prod_name = '$prod_name' AND prod_id = '$prod_id' "; $stmt = $connect->prepare($sql); //$stmt->bindValue(':qty', $prod_qty, PDO::PARAM_STR); $stmt->bindValue(':prod_name', $prod_name, PDO::PARAM_STR); $stmt->bindValue(':prod_id', $prod_id, PDO::PARAM_STR); $stmt->execute(); echo '<div class="alert bg-success text-center">ITEMS ADDED</div>'; unset($_SESSION["shopping_cart"]); }else{ echo '<div class="alert bg-danger text-center">A PROBLEM OCCURRED</div>'; } }
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.