Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by I-AM-OBODO

  1. This is what i did and the error: Fatal error: Cannot pass parameter 2 by reference $update = $pdo->prepare(" UPDATE stocks SET item_qty = :item_qty WHERE category = :category AND product_name = :product_name AND item_size = :item_size AND item_type = :item_type "); foreach($_POST['category'] as $k => $category){ $update->bindParam(':item_qty', $item_q - $_POST['item_qty'][$k]); $update->bindParam(':product_name', $_POST['product_name'][$k]); $update->bindParam(':item_type', $_POST['item_type'][$k]); $update->bindParam(':item_size', $_POST['item_size'][$k]); $update->execute(); }
  2. Good day. I still havent been able to update the stocks. I have tried so many things and encountered various errors: Cannot pass parameter 2 by reference Fatal error: Cannot pass parameter 2 by reference Please can you help me with the update stuff? Thanks
  3. Thanks. but am working on the form type version. Will look at the other version later. thanks
  4. Hello, I tried doing some deduction from another table but its giving me Array to string conversion $update = $pdo->prepare(" UPDATE stocks SET item_qty = item_qty - '$_POST[item_qty]' WHERE category = '$category' AND product_name = '$_POST[product_name]' AND item_type = '$_POST[item_type]' AND item_size = '$_POST[item_size]' "); $update->execute();
  5. Thank you very much. All seem to be working well for now. I had to delete the table and start all over again. The form version is working well.
  6. I cant seem to locate trans_id and the error is reporting as duplicate should be trans_ref and not trans_id. however, the trans_ref is the reference for the transaction. since we can have multiple items in a single transaction/session. thanks
  7. oops! oversight. this is what i got: Array ( [category] => Array ( [0] => Beverages [1] => Milk [2] => Cereals [3] => Beverages [4] => Milk ) [product_name] => Array ( [0] => Bournvita [1] => Dano [2] => Golden morn [3] => Milo [4] => Peak ) [item_type] => Array ( [0] => Refill [1] => Evap [2] => NONE [3] => Tin [4] => Evap ) [item_size] => Array ( [0] => 1 [1] => 160 [2] => 1 [3] => 500 [4] => 380 ) [item_qty] => Array ( [0] => 4 [1] => 2 [2] => 3 [3] => 2 [4] => 3 ) [item_price] => Array ( [0] => 1800 [1] => 1400 [2] => 1800 [3] => 1700 [4] => 1400 ) [price] => Array ( [0] => 7200 [1] => 2800 [2] => 5400 [3] => 3400 [4] => 4200 ) [total_price] => ₦23,000.00 [send] => Complete Shopping ) and error is: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '799988' for key 'trans_id'' but the first item is inserted into the database Thanks
  8. Yeah. I have read it. But this error: Warning: Invalid argument supplied for foreach() is from your own code: the line number is 127: foreach ($_POST['category'] as $k => $category) {
  9. Array ( [category] => Milk [product_name] => Peak [item_type] => Refill [item_size] => 380 [item_qty] => 2 [item_price] => 3500 [price] => 7000 [total_price] => ₦26,300.00 [send] => Complete Shopping )
  10. Thanks so very much. Will try out your second option and the table normalization once i get this up and running. But i have having error on your first code: Warning: Invalid argument supplied for foreach() Thanks
  11. Sorry. And thanks for your time. Its no guessing game. I omitted the where the data is coming from. I used a form cos i feel it will work for the purpose, cos i tried to use SELECT, INSERT but since the first table and destination table does not have the same number of rows, it didnt work or I couldnt get it to work and so i decided to use form. The previous code is the POST. Below is the rest of the code $stmt = $pdo->prepare("SELECT * FROM temp_shopping"); $stmt->execute(); $num_rows = $stmt->rowCount(); if($num_rows < 1){ echo '<div class="alert bg-danger text-center">NO RECORD FOUND</div>'; }else{ $total_price = 0; $stmt = $pdo->query(" SELECT * FROM temp_shopping WHERE trans_ref = '$_SESSION[trans_ref]' ORDER BY product_name ASC " ); echo "<form action='' method='post'>"; echo "<table width='100%'>"; echo "<tr> <th>Category</th> <th>Product Name</th> <th>Product Type</th> <th>Size</th> <th>Qty</th> <th>Unit Price</th> <th>Total</th> </tr>"; // keeps getting the next row until there are no more to get while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Print out the contents of each row into a table echo "<tr><td>"; echo "<input type='text' class='form-control' name='category' value='".$row['category']."' readonly /> "; echo "</td><td>"; echo "<input type='text' class='form-control' name='product_name' value='".$row['product_name']."' readonly /> "; echo "</td><td>"; echo "<input type='text' class='form-control' name='item_type' size='7' value='".$row['item_type']."' readonly /> "; echo "</td><td>"; echo "<input type='text' class='form-control' name='item_size' size='5' value='".$row['item_size']."' readonly /> "; echo "</td><td>"; echo "<input type='text' class='form-control' name='item_qty' size='5' value='".$row['item_qty']."' readonly /> "; echo "</td><td>"; echo "<input type='text' class='form-control' name='item_price' size='7' value='".$row['item_price']."' readonly /> "; echo "</td><td>"; echo "<input type='text' class='form-control' name='price' size='7' value='".$row['item_price'] * $row['item_qty']."' readonly /> "; $total_price += $row['item_price'] * $row['item_qty']; echo "</td></tr>"; } echo "<tr>"; echo "<td colspan='6' align='right'>"; echo "<strong>TOTAL PRICE :</strong>"; echo "</td>"; echo "<td align='left'>"; echo "<strong><input type='text' class='form-control' name='total_price' size='7' value='"."₦".number_format($total_price,2)."' readonly /> "; echo "</td>"; echo "</tr>"; echo "</table>"; }
  12. The data on the form is derived from(a while loop) in a temporal table in the database. From there the data and the summation(total) is to be stored the the actual table. But the problem am having is that only the last row is being inserted into the actual table. Thanks
  13. What do you mean by get rid of the variables for nothing?
  14. Hi guys, I have a table that i want all the entries to be inserted all at once. Mine is just inserting only one of the item, how can i get it to work? I also attached a sample table. Thanks if(isset($_POST['send'])){ $category = $_POST['category']; $item_type = $_POST['item_type']; $item_size = $_POST['item_size']; $product_name = $_POST['product_name']; $item_qty = $_POST['item_qty']; $price = $_POST['price']; $total_price = $_POST['total_price']; $item_price = $_POST['item_price']; $sql = " INSERT INTO shopping( trans_ref, category, product_name, item_type, item_size, item_qty, item_price, price, date ) VALUES( :trans_ref, :category, :product_name, :item_type, :item_size, :item_qty, :item_price, :price, NOW() ) "; $stmt = $pdo->prepare($sql); $stmt->execute(array( ':trans_ref' => $_SESSION['trans_ref'], ':category' => $category, ':product_name' => $product_name, ':item_type' => $item_type, ':item_size' => $item_size, ':item_qty' => $item_qty, ':item_price' => $item_price, ':price' => $price )); if ( $stmt->rowCount()){ echo '<div class="alert bg-success text-center">SHOPPING COMPLETED</div>'; }else{ echo '<div class="alert bg-danger text-center">SHOPPING NOT COMPLETED. A PROBLE OCCURED</div>'; } }
  15. oops! was doing the wrong thing all the while. Thanks all. Resolved
  16. Hi guys, I have a form that the reference_id is auto generated and is stored in a session. Is there a way to use only the first auto generated reference_id until the session is unset or destroyed? thanks
  17. yeah i know. but the problem is that i want to get all the values from a form, then list them just like a shopping cart where u find all the added items before continue shopping or checkouts. i guess its a multi-dimensional array. maybe am wrong though. thanks
  18. I dont get you? for instance now, i want value of only the user_name and instead of outputting "obodo" it gives error. and you said $value is not an array?
  19. Hi guys, why am i getting this error: Illegal string offset 'user_id' but when echo $value it brings the correct output. Thanks $user_id = 5; $user_name = "obodo"; $_SESSION['test'] = array('user_id' => $user_id, 'user_name' => $user_name); foreach( $_SESSION['test'] as $value ) { echo $value['user_id']; //give error /* echo $value //works */ }
  20. Am not really after the calculation, what I'm concerned about is retrieving the value of price based on selected products so that the price shows up on the price input area for further processing. If I get this, my job is halve done (assuming I'm sticking with dropdown option)
  21. Ok. The app is gonna run on WAMP. So the issue of slow server is to a great extent eliminated. The system will have a good CPU and RAM for speed. Will have to think of something and if nothing comes handy, will make do with the dropdown/select option. Thanks guys.
  22. I quite agree with you. But this is to be used for small scale sales shop that sells confectioneries basically and few other stuffs. It's just to add glamour to the shop and also keep records of sales/profits. Using thumbnail/image will it not be tedious for the sales rep. Cos basically it's the sales rep only that does the shopping and the customer is issued receipt. Now I really should change/abandon my initial perception. What do u think? Any idea is highly welcomed.
  • 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.