Guest User

Untitled

a guest
Feb 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2. if(!empty($_POST["save"])) {
  3. $con = @mysqli_connect("localhost", "root", "", "demo_jhacko");
  4. if ($con->connect_error) {
  5. echo "Error: " . $con->connect_error;
  6. exit();
  7. }
  8. $itemCount = count($_POST["item_name"]);
  9. $itemValues=0;
  10. $query = ("INSERT INTO barang (nama_barang,harga_barang) VALUES");
  11. $queryValue = "";
  12. for($i=0;$i<$itemCount;$i++) {
  13. if(!empty($_POST["item_name"][$i]) || !empty($_POST["item_price"][$i])) {
  14. $itemValues++;
  15. if($queryValue!="") {
  16. $queryValue .= ",";
  17. }
  18. $queryValue .= "('" . $_POST["item_name"][$i] . "', '" . $_POST["item_price"][$i] . "')";
  19. }
  20. }
  21. $sql = $query.$queryValue;
  22. if($itemValues!=0) {
  23. $result = mysqli_query($con,$sql);
  24. if(!empty($result)) $message = "Berhasil Menambahkan barang.";
  25. }
  26. }
Add Comment
Please, Sign In to add comment