Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.11 KB | None | 0 0
  1. products.php
  2. <?php
  3.     include 'config/connection.php';
  4. ?>
  5. <!DOCTYPE html>
  6. <html lang="en">
  7. <head>
  8.     <meta charset="UTF-8">
  9.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  10.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  11.     <title>Document</title>
  12. </head>
  13. <body>
  14.     <center><h1>DATA PRODUCTS</h1></center>
  15.     <a href = "add_product.php"><p align ="right"><button>Add Data Product</button></p></p></a>
  16.     <table align = "center" width="95%" border = "1">
  17.         <tr>
  18.             <td>No</td>
  19.             <td>Nama Suplier</td>
  20.             <td>Brand</td>
  21.             <td>Price</td>
  22.             <td>Volume</td>
  23.             <td>Created</td>
  24.             <td>Modified</td>
  25.             <td>Action</td>
  26.         </tr>
  27.         <?php
  28.             $no = 1;
  29.             $sql = "SELECT s.name, p.* FROM products p, supliers s WHERE s.id = p.suplier_id"; //membuat query
  30.             //echo $sql;
  31.             $exe = mysqli_query($conn, $sql); // menjalankan query
  32.             while($row = mysqli_fetch_array($exe)){
  33.                // $id_sup = $row['suplier_id'];
  34.               //  $sql_sup = "SELECT name FROM supliers WHERE id = '$id_sup'";
  35.                 //echo $sql_sup;
  36.               //  $exe_sup = mysqli_query($conn, $sql_sup);
  37.               //  $row_sup = mysqli_fetch_array($exe_sup);
  38.         ?>
  39.         <tr>
  40.             <td><?=$no++?></td>
  41.             <td><?=$row['name']?></td>
  42.             <td><?php echo $row['brand'];?></td>
  43.             <td><?=$row['price']?></td>
  44.             <td><?php echo $row['volume'];?></td>
  45.             <td><?php echo $row['created'];?></td>
  46.             <td><?php echo $row['modified'];?></td>
  47.             <td><a href = "product_edit.php?id=<?=$row['id']?>"> Edit</a> | <a href = "product_delete.php?id=<?=$row['id']?>">DELETE</a></td>
  48.         </tr>
  49.         <?php
  50.             }
  51.         ?>
  52.     </table>
  53. </body>
  54. </html>
  55.  
  56. product_edit.php
  57. <?php
  58.     include 'config/connection.php';
  59.  
  60.     //$nama;
  61.     $id = $_GET['id'];
  62.     //echo $id;
  63.     if (isset($_REQUEST['edit'])) {
  64.         # code...
  65.        $id = $_REQUEST['id'];
  66.         $suplier_id = $_REQUEST['suplier'];
  67.         $brand      = $_REQUEST['brand'];
  68.         $price      = $_REQUEST['price'];
  69.         $volume     = $_REQUEST['volume'];
  70.         $modified    = date('Y/m/d h:m:s');
  71.  
  72.         //echo $suplier_id.", ".$brand.", ".$price.", ".$volume.", ".$created.", ".$modified;
  73.        
  74.         $sql = "UPDATE products SET brand = '$brand', price = '$price', volume = '$volume', modified = '$modified' WHERE id = '$id'";
  75.         //echo $sql;
  76.         $exe = mysqli_query($conn, $sql);
  77.         if ($exe) {
  78.             # code...
  79.            echo "<script>alert('ubah data berhasil'); document.location.href = 'products.php';</script>";
  80.         } else{
  81.             echo "<script>alert('ubah data gagal'); document.location.href = 'products.php';</script>";
  82.  
  83.         }
  84.      }
  85.  
  86. ?>
  87. <!DOCTYPE html>
  88. <html lang="en">
  89. <head>
  90.     <meta charset="UTF-8">
  91.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  92.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  93.     <title>Document</title>
  94. </head>
  95. <body>
  96.     <center><h1>Add Data Product</h1></center>
  97.     <form>
  98.     <?php
  99.         $query_edit = "SELECT * FROM products WHERE id = '$id'";
  100.         $exe_edit = mysqli_query($conn, $query_edit);
  101.         $row_edit = mysqli_fetch_array($exe_edit);
  102.  
  103.         // echo $row['brand']."</br />";
  104.         // echo $row['price']."</br />";
  105.         // echo $row['volume']."</br />";
  106.     ?>
  107.         <table align = "center">
  108.             <tr>
  109.                 <td>Suplier</td>
  110.                 <td>:</td>
  111.                 <td>
  112.                     <select name ="suplier">
  113.                         <?php
  114.                             $sql_sup = "SELECT id, name FROM supliers";
  115.                             $exe = mysqli_query($conn, $sql_sup);
  116.                             while($row = mysqli_fetch_array($exe)){
  117.                         ?>
  118.                         <option value="<?=$row['id']?>"><?=$row['name']?></option>
  119.                         <?php
  120.                             }
  121.                         ?>
  122.                     </select>
  123.                 </td>
  124.             <tr>
  125.            
  126.             <tr>
  127.                 <td>Brand</td>
  128.                 <td>:</td>
  129.                 <td>
  130.                 <input type = "hidden" name = "id" value = "<?=$row_edit['id']?>">
  131.                 <input type = "text" name = "brand" value = "<?=$row_edit['brand']?>">
  132.                 </td>
  133.             <tr>
  134.             <tr>
  135.                 <td>Price</td>
  136.                 <td>:</td>
  137.                 <td><input type = "text" name = "price" value = "<?=$row_edit['price']?>"></td>
  138.             <tr>
  139.             <tr>
  140.                 <td>Volume</td>
  141.                 <td>:</td>
  142.                 <td><input type = "text" name = "volume" value = "<?=$row_edit['volume']?>"></td>
  143.             <tr>
  144.             <tr>
  145.                 <td></td>
  146.                 <td></td>
  147.                 <td><input type = "submit" value = "SAVE" name = "edit"></td>
  148.             <tr>
  149.         </table>
  150.     </form>
  151. </body>
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement