Jump to content

I-AM-OBODO

Members
  • Posts

    439
  • Joined

  • Last visited

Everything posted by I-AM-OBODO

  1. 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.
  2. 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
  3. 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
  4. 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) {
  5. 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 )
  6. 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
  7. 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>"; }
  8. 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
  9. What do you mean by get rid of the variables for nothing?
  10. 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>'; } }
  11. oops! was doing the wrong thing all the while. Thanks all. Resolved
  12. 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
  13. 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
  14. 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?
  15. 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 */ }
  16. 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)
  17. 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.
  18. 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.
  19. The calculation is not the problem for now as I can do it either later on as the products are populated. The main issue I have now is to retrieve prices based on selection
  20. Am not saying I cannot retrieve the value for the prices. What I want is for the price to auto populate once the product is selected and that can't be done with php alone I guess
  21. How do I get the price based on the selected product firstly?
  22. Hi all, How can i auto populate the price of an item based on a chosen product and then auto calculate the price and quantity before hitting the ADD button. I think it should be a javascript/ajax/jquery stuff but dont know how to go about it. The Unit price should be auto populated based on valu from the database. The amount is the Unit Price times the Quantity of the Product Selected. Thanks My form <form action="" method="post" data-toggle="validator"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Item Name</label> <select id="username" name="item_name" class="form-control inputs" data-error="Select Item" required> <option value="">Chose Item</option> <?php $stmt = $pdo->query(" SELECT item_name FROM stocks ORDER BY item_name ASC "); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $item_name = $row['item_name']; echo "<option value=\"$item_name\"> $item_name </option>"; } ?> </select> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-2"> <div class="form-group"> <label>Unit Price</label> <input type="number" class="form-control" name="item_price"> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-2"> <div class="form-group"> <label>Item Quantity</label> <input type="number" class="form-control" name="item_qty" required data-error="Stock Quantity is missing"> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-2"> <div class="form-group"> <label>Amount</label> <input type="number" class="form-control" name="amount" > <div class="help-block with-errors"></div> </div> </div> </div> <br> <span class="input-group-btn"> <input name="send" type="submit" class="btn btn-danger btn-form display-4 rounded" value="ADD"> </span> </form>
  23. The dear username shouldnt be of any worries to you and that isnt my problem either. my problem is getting the script to send just one mail containing all the bills. just so you know: it is dear username which translates to: dear myemailaddress.com
×
×
  • 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.