Advertisement
noam76

insert to table dropdown-list

Apr 17th, 2020
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.72 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3. include("con.php"); //insert data server
  4.  
  5. try {
  6.   // read from products table
  7.   $sqlproducts = "SELECT product_name, product_number FROM products ORDER BY product_name ASC";
  8.   $stmt1 = $pdo->prepare($sqlproducts);
  9.   $stmt1->execute();
  10.   $resultsproducts = $stmt1->fetchAll(PDO::FETCH_ASSOC);
  11.   // read from suppliers table
  12.   $sqlsuppliers = "SELECT supplier_name, ID FROM suppliers ORDER BY supplier_name ASC";
  13.   $stmt2 = $pdo->prepare($sqlsuppliers);
  14.   $stmt2->execute();
  15.   $resultssupliers = $stmt2->fetchAll(PDO::FETCH_ASSOC);
  16.  
  17.   if($_SERVER['REQUEST_METHOD'] == 'POST') {
  18.     $pdo->beginTransaction();
  19.     $prodnumber = $_REQUEST["output"];
  20.     $suppliernumber = $_REQUEST["output1"];
  21.     $amount = $_POST['amount'];
  22.     $project_number = 0;
  23.     $amount_out = 0;
  24.    /*
  25.     echo "Prod:";
  26.     echo $prodnumber;
  27.     echo '<br>';
  28.     echo "Supplier:";
  29.     echo $suppliernumber;
  30.     echo '<br>';
  31.     echo "Amount:";
  32.     echo $amount;
  33.     echo '<br>';
  34.    */
  35.     if(empty($prodnumber) || empty($suppliernumber) || empty($amount)) {
  36.     ?>
  37.      <div id="dialog-message" title="שגיאה">
  38.       <p align="right">
  39.        <span class="ui-icon ui-icon-circle-close" style="float:right; margin:0 7px 50px 0;"></span>
  40.         יש למלא את כל השדות
  41.       </p>
  42.      </div>
  43.     <?php
  44.     } else {
  45.     $sql = "INSERT INTO inventory_stock (product_number, supplier_ID, project_number, amount_in, amount_out) VALUES (:product_number, :supplier_ID, :project_number, :amount_in, :amount_out)";
  46.     $stmt = $pdo->prepare($sql);      
  47.     $stmt->execute(['product_number' => $prodnumber, 'supplier_ID' => $suppliernumber, 'project_number' => $project_number, 'amount_in' => $amount, 'amount_out' => $amount_out]);
  48.     $pdo->commit();
  49.     ?>
  50.      <div id="dialog-message" title="הצלחה">
  51.       <p align="right" >
  52.        <span class="ui-icon ui-icon-circle-check" style="float:right; margin:0 7px 50px 0;"></span>
  53.        נקלט בהצלחה
  54.       </p>
  55.      </div>
  56.     <?php
  57.     }
  58.   }
  59.   $prodnumber = "";
  60.   $suppliernumber = "";
  61.   $amount = "";
  62. }
  63.  
  64. catch(Exception $e){
  65.   $pdo->rollBack();
  66.   ?>
  67.   <div id="dialog-message" title="שגיאה">
  68.    <p align="right">
  69.     <span class="ui-icon ui-icon-circle-close" style="float:right; margin:0 7px 50px 0;"></span>
  70.      שגיאה! לא נעשה עדכון
  71.    </p>
  72.   </div>
  73.   <?php
  74.   echo "<br>" . 'N° : '.$e->getCode();
  75.   echo "<br>" . 'Error : '.$e->getMessage();
  76.   $pdo = null;
  77. }
  78. ?>
  79.  
  80. <html lang="en">
  81. <head>
  82.     <meta charset="UTF-8">
  83.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  84.     <link rel = "stylesheet" type = "text/css" href = "myStyle.css"/>
  85.     <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  86.     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  87.     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  88.     <title>הכנסה למלאי</title>
  89.     <style>
  90.     .form-control {
  91.      border: -1px solid #ccc;
  92.      text-align: right;
  93.     }
  94.     </style>
  95. </head>
  96. <body>
  97.  <form action="" method="POST" class="form-style-9">
  98.  <div align="right">
  99.      <H1 align="right">מלאי נכנס</H1>
  100.   <ul>
  101.     <li>
  102.     <!-- שם מוצר ושמירת המק"ט -->
  103.     <select class="field-style field-split align-left" name='productsnumber' onChange='outputValue(this)'>
  104.     <option value='' selected disabled>בחר מוצר</option>
  105.     <?php foreach($resultsproducts as $row)
  106.     {
  107.       echo "<option value='" . $row['product_number'] . "'>" . $row['product_name'] . "</option>";
  108.     }?>    
  109.     </select>
  110.     <input type='hidden' id='output' name='output' readonly />
  111.     </li>
  112.    
  113.     <li>
  114.     <!-- שם הספק -->
  115.     <select class="field-style field-split align-right" name='suppliersnumber' onChange='outputValue1(this)'>
  116.     <option value='' selected disabled>בחר שם הספק</option>
  117.     <?php foreach($resultssupliers as $row)
  118.     {
  119.       echo "<option value='" . $row['ID'] . "'>" . $row['supplier_name'] . "</option>";
  120.     }?>    
  121.     </select>
  122.     <input type='hidden' id='output1' name='output1' readonly />
  123.      
  124.     <input type="number" name="amount" placeholder="הכנס כמות" class="field-style field-split align-left " />
  125.    
  126.     <li>
  127.      <input type="submit" value="הכנס מלאי חדש" style = "font-size:20px; float:right">
  128.     </li>
  129.   </ul>
  130.  </div>
  131.  </form>
  132. </body>
  133. </html>
  134. <script>
  135. function outputValue(item)
  136. {
  137.  document.getElementById('output').value = item.value;
  138. }
  139. function outputValue1(item)
  140. {
  141.  document.getElementById('output1').value = item.value;
  142. }
  143.  
  144. $( function(){
  145.   $( "#dialog-message" ).dialog({
  146.     modal: true,
  147.     buttons: {
  148.      Ok: function() {
  149.       $( this ).dialog( "close" );
  150.      }
  151.     }
  152.   });
  153. });
  154. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement