Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Modal - Add Item -->
- <div class="modal fade" id="add_pitem" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
- <h4 class="modal-title" id="myModalLabel">Add New Item </h4>
- </div>
- <div class="modal-body">
- <?php
- $conn->close();
- $servername = "localhost"; $username = "root"; $password = ""; $db = "store";
- $conn = new mysqli($servername, $username, $password, $db);
- if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}
- $res = mysqli_query($conn,"SHOW TABLES");
- echo "<div class='form-group'><label for='selectstore'>Select an store</label></div>";
- echo "<select name='selectstore' id='selectstore'>";
- while($row = mysqli_fetch_array($res))
- {
- echo "<option value='" . $row[0] . "'>" . $row[0] . "</option>"; }
- echo "<input type='hidden' name='table' value='$table'></select>";
- ?>
- <div class="form-group"><label for="pitem">Item</label>
- <select name="pitem" id="pitem"><option value="">Select Store first</option>
- <input type='hidden' name='table' value='<? echo '$table'; ?>'></select></div>
- <div class="form-group"><label for="pquantity">Quantity</label>
- <input type="text" id="pquantity" placeholder="Select Item first" class="form-control"/></div>
- <div class="form-group"><label for="remarks">Remarks</label>
- <input type="text" id="remarks" placeholder="Remarks" class="form-control"/></div>
- <?php
- $conn->close();
- $server = "localhost";
- $username = "root";
- $password = "";
- $dbname = "project";
- $conn = new mysqli($server, $username, $password, $dbname);
- if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);}
- ?></div>
- <div class="modal-footer">
- <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
- <button type="button" class="btn btn-primary" onclick="add_pitem()">Add Item</button>
- </div>
- </div>
- </div>
- </div>
- <!-- // Modal -->
- $(document).ready(function(){
- $('#selectstore').on('change',function(){
- var selectstore = $(this).val();
- if(selectstore){
- $.ajax({
- type:'POST',
- url:'loaditem.php',
- data:'selectstore='+selectstore,
- success:function(html){
- $('#pitem').html(html);
- $('#pquantity').html('<div class="form-group"><label for="quantity">Quantity</label><input type="text" id="quantity" placeholder="Select item first" class="form-control"/></div>');
- }
- });
- }else{
- $('#pitem').html('<option value="">Select Store first</option>');
- $('#pquantity').html('<div class="form-group"><label for="quantity">Quantity</label><input type="text" id="quantity" placeholder="Select item first" class="form-control"/></div>');
- }
- });
- $('#pitem').on('change',function(){
- var pitem = $(this).val();
- if(pitem){
- $.ajax({
- type:'POST',
- url:'loaditem.php',
- data:'pitem='+pitem,
- success:function(html){
- $('#pquantity').html(html);
- }
- });
- }else{
- $('#pquantity').html('<div class="form-group"><label for="quantity">Quantity</label><input type="text" id="quantity" placeholder="Select item first" class="form-control"/></div>');
- }
- });
- });
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "store";
- $table = $_POST['table'];
- $selectstore = $_POST['selectstore'];
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);}
- if(isset($_POST["selectstore"]) && !empty($_POST["selectstore"])){
- $res = mysqli_query($conn,"SHOW TABLES");
- echo "<div class='form-group'><label for='selectstore'>Select an store</label></div>";
- echo "<select name='selectstore' id='selectstore'>";
- while($row = mysqli_fetch_array($res))
- {echo "<option value='" . $row[0] . "'>" . $row[0] . "</option>"; }
- echo "<input type='hidden' name='table' value='$table'></select>";}
- if(isset($_POST["pitem"]) && !empty($_POST["pitem"])){
- $query = $db->query("SELECT quantity FROM `".$table."` WHERE item = `".$_POST['pitem']."` ");
- $rowCount = $query->num_rows;
- if($rowCount > 0){
- echo '<div class="form-group"><label for="pquantity">Quantity</label>';
- while($row = $query->fetch_assoc()){
- echo '<input type="text" id="pquantity" placeholder="available maximum quantity is '.$row['item'].'" class="form-control"/></div>';
- }
- }else{ echo '<div class="form-group"><label for="quantity">No Quantity Available</label></div>';
- }}
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement