Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. <!-- Modal - Add Item -->
  2. <div class="modal fade" id="add_pitem" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  3. <div class="modal-dialog" role="document">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  7. <h4 class="modal-title" id="myModalLabel">Add New Item </h4>
  8. </div>
  9. <div class="modal-body">
  10.  
  11. <?php
  12. $conn->close();
  13. $servername = "localhost"; $username = "root"; $password = ""; $db = "store";
  14. $conn = new mysqli($servername, $username, $password, $db);
  15. if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}
  16.  
  17. $res = mysqli_query($conn,"SHOW TABLES");
  18. echo "<div class='form-group'><label for='selectstore'>Select an store</label></div>";
  19. echo "<select name='selectstore' id='selectstore'>";
  20. while($row = mysqli_fetch_array($res))
  21. {
  22. echo "<option value='" . $row[0] . "'>" . $row[0] . "</option>"; }
  23. echo "<input type='hidden' name='table' value='$table'></select>";
  24. ?>
  25. <div class="form-group"><label for="pitem">Item</label>
  26. <select name="pitem" id="pitem"><option value="">Select Store first</option>
  27. <input type='hidden' name='table' value='<? echo '$table'; ?>'></select></div>
  28. <div class="form-group"><label for="pquantity">Quantity</label>
  29. <input type="text" id="pquantity" placeholder="Select Item first" class="form-control"/></div>
  30. <div class="form-group"><label for="remarks">Remarks</label>
  31. <input type="text" id="remarks" placeholder="Remarks" class="form-control"/></div>
  32. <?php
  33. $conn->close();
  34. $server = "localhost";
  35. $username = "root";
  36. $password = "";
  37. $dbname = "project";
  38. $conn = new mysqli($server, $username, $password, $dbname);
  39. if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);}
  40. ?></div>
  41. <div class="modal-footer">
  42. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  43. <button type="button" class="btn btn-primary" onclick="add_pitem()">Add Item</button>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <!-- // Modal -->
  49.  
  50. $(document).ready(function(){
  51. $('#selectstore').on('change',function(){
  52. var selectstore = $(this).val();
  53. if(selectstore){
  54. $.ajax({
  55. type:'POST',
  56. url:'loaditem.php',
  57. data:'selectstore='+selectstore,
  58. success:function(html){
  59. $('#pitem').html(html);
  60. $('#pquantity').html('<div class="form-group"><label for="quantity">Quantity</label><input type="text" id="quantity" placeholder="Select item first" class="form-control"/></div>');
  61. }
  62. });
  63. }else{
  64. $('#pitem').html('<option value="">Select Store first</option>');
  65. $('#pquantity').html('<div class="form-group"><label for="quantity">Quantity</label><input type="text" id="quantity" placeholder="Select item first" class="form-control"/></div>');
  66. }
  67. });
  68.  
  69. $('#pitem').on('change',function(){
  70. var pitem = $(this).val();
  71. if(pitem){
  72. $.ajax({
  73. type:'POST',
  74. url:'loaditem.php',
  75. data:'pitem='+pitem,
  76. success:function(html){
  77. $('#pquantity').html(html);
  78. }
  79. });
  80. }else{
  81. $('#pquantity').html('<div class="form-group"><label for="quantity">Quantity</label><input type="text" id="quantity" placeholder="Select item first" class="form-control"/></div>');
  82. }
  83. });
  84. });
  85.  
  86. <?php
  87. $servername = "localhost";
  88. $username = "root";
  89. $password = "";
  90. $dbname = "store";
  91. $table = $_POST['table'];
  92. $selectstore = $_POST['selectstore'];
  93. $conn = new mysqli($servername, $username, $password, $dbname);
  94. if ($conn->connect_error) {
  95. die("Connection failed: " . $conn->connect_error);}
  96.  
  97. if(isset($_POST["selectstore"]) && !empty($_POST["selectstore"])){
  98.  
  99. $res = mysqli_query($conn,"SHOW TABLES");
  100. echo "<div class='form-group'><label for='selectstore'>Select an store</label></div>";
  101. echo "<select name='selectstore' id='selectstore'>";
  102. while($row = mysqli_fetch_array($res))
  103. {echo "<option value='" . $row[0] . "'>" . $row[0] . "</option>"; }
  104. echo "<input type='hidden' name='table' value='$table'></select>";}
  105.  
  106. if(isset($_POST["pitem"]) && !empty($_POST["pitem"])){
  107. $query = $db->query("SELECT quantity FROM `".$table."` WHERE item = `".$_POST['pitem']."` ");
  108. $rowCount = $query->num_rows;
  109. if($rowCount > 0){
  110. echo '<div class="form-group"><label for="pquantity">Quantity</label>';
  111. while($row = $query->fetch_assoc()){
  112. echo '<input type="text" id="pquantity" placeholder="available maximum quantity is '.$row['item'].'" class="form-control"/></div>';
  113. }
  114. }else{ echo '<div class="form-group"><label for="quantity">No Quantity Available</label></div>';
  115. }}
  116. $conn->close();
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement