Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- products.php
- <?php
- include 'config/connection.php';
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- </head>
- <body>
- <center><h1>DATA PRODUCTS</h1></center>
- <a href = "add_product.php"><p align ="right"><button>Add Data Product</button></p></p></a>
- <table align = "center" width="95%" border = "1">
- <tr>
- <td>No</td>
- <td>Nama Suplier</td>
- <td>Brand</td>
- <td>Price</td>
- <td>Volume</td>
- <td>Created</td>
- <td>Modified</td>
- <td>Action</td>
- </tr>
- <?php
- $no = 1;
- $sql = "SELECT s.name, p.* FROM products p, supliers s WHERE s.id = p.suplier_id"; //membuat query
- //echo $sql;
- $exe = mysqli_query($conn, $sql); // menjalankan query
- while($row = mysqli_fetch_array($exe)){
- // $id_sup = $row['suplier_id'];
- // $sql_sup = "SELECT name FROM supliers WHERE id = '$id_sup'";
- //echo $sql_sup;
- // $exe_sup = mysqli_query($conn, $sql_sup);
- // $row_sup = mysqli_fetch_array($exe_sup);
- ?>
- <tr>
- <td><?=$no++?></td>
- <td><?=$row['name']?></td>
- <td><?php echo $row['brand'];?></td>
- <td><?=$row['price']?></td>
- <td><?php echo $row['volume'];?></td>
- <td><?php echo $row['created'];?></td>
- <td><?php echo $row['modified'];?></td>
- <td><a href = "product_edit.php?id=<?=$row['id']?>"> Edit</a> | <a href = "product_delete.php?id=<?=$row['id']?>">DELETE</a></td>
- </tr>
- <?php
- }
- ?>
- </table>
- </body>
- </html>
- product_edit.php
- <?php
- include 'config/connection.php';
- //$nama;
- $id = $_GET['id'];
- //echo $id;
- if (isset($_REQUEST['edit'])) {
- # code...
- $id = $_REQUEST['id'];
- $suplier_id = $_REQUEST['suplier'];
- $brand = $_REQUEST['brand'];
- $price = $_REQUEST['price'];
- $volume = $_REQUEST['volume'];
- $modified = date('Y/m/d h:m:s');
- //echo $suplier_id.", ".$brand.", ".$price.", ".$volume.", ".$created.", ".$modified;
- $sql = "UPDATE products SET brand = '$brand', price = '$price', volume = '$volume', modified = '$modified' WHERE id = '$id'";
- //echo $sql;
- $exe = mysqli_query($conn, $sql);
- if ($exe) {
- # code...
- echo "<script>alert('ubah data berhasil'); document.location.href = 'products.php';</script>";
- } else{
- echo "<script>alert('ubah data gagal'); document.location.href = 'products.php';</script>";
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- </head>
- <body>
- <center><h1>Add Data Product</h1></center>
- <form>
- <?php
- $query_edit = "SELECT * FROM products WHERE id = '$id'";
- $exe_edit = mysqli_query($conn, $query_edit);
- $row_edit = mysqli_fetch_array($exe_edit);
- // echo $row['brand']."</br />";
- // echo $row['price']."</br />";
- // echo $row['volume']."</br />";
- ?>
- <table align = "center">
- <tr>
- <td>Suplier</td>
- <td>:</td>
- <td>
- <select name ="suplier">
- <?php
- $sql_sup = "SELECT id, name FROM supliers";
- $exe = mysqli_query($conn, $sql_sup);
- while($row = mysqli_fetch_array($exe)){
- ?>
- <option value="<?=$row['id']?>"><?=$row['name']?></option>
- <?php
- }
- ?>
- </select>
- </td>
- <tr>
- <tr>
- <td>Brand</td>
- <td>:</td>
- <td>
- <input type = "hidden" name = "id" value = "<?=$row_edit['id']?>">
- <input type = "text" name = "brand" value = "<?=$row_edit['brand']?>">
- </td>
- <tr>
- <tr>
- <td>Price</td>
- <td>:</td>
- <td><input type = "text" name = "price" value = "<?=$row_edit['price']?>"></td>
- <tr>
- <tr>
- <td>Volume</td>
- <td>:</td>
- <td><input type = "text" name = "volume" value = "<?=$row_edit['volume']?>"></td>
- <tr>
- <tr>
- <td></td>
- <td></td>
- <td><input type = "submit" value = "SAVE" name = "edit"></td>
- <tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement