Update, Delete And Reserve Product In PHP

Update, Delete And Reserve Product In PHP, in this tutorial i will teach you how this application created in PHP. This simple tutorial updates the products and the quantity of every data of product. You can also Delete and Reserve a products that you want to reserve. Each product that you've been reserved has based on the day that you issued and the day that you want it to pick the product. Every reserved product has been recorded to the list of reserved users. Here are the sample script that i will show you.

Sample Code

PHP Script For the Products List.
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Update, Delete & Reserve Products</title>
  6. </head>
  7. <body>
  8. <center><div id="header"><h1 class="header-text">Update, Delete & Reserve Products</h1><div id=menu-modal>
  9.         <a href="index.php"><button id="b1" class="btn btn-primary ">&nbspHome</button></a>
  10.         <a href="viewreserved.php"><button id="b2" class="btn btn-primary ">&nbspView Reserved Products</button></a>
  11. </div></div></center>
  12. <div id="container2">
  13.         <div class="form_head" align="center">List Of Products</div><br>
  14.                 <div class="control-group">
  15.                     <table name="booklist" id="dtable" width="900">
  16.                         <thead>
  17.                                 <th>Product ID</th>
  18.                                 <th>Product Name</th>
  19.                                 <th>Product Category</th>
  20.                                 <th>Product Quantity</th>
  21.                                 <th>Function</th>
  22.                         </thead>
  23. <tbody>
  24. <?php
  25.         include "dbconnect.php";
  26.         $q="select * from tblproducts order by prod_id asc";
  27.         $result = mysql_query($q);
  28.         while($rs=mysql_fetch_array($result)){
  29.         $prodid=$rs['prod_id'];
  30.         $prodname=$rs['prod_name'];
  31.         $categ=$rs['prod_ctry'];
  32.         $qty=$rs['prod_qty'];
  33.         echo "<tr class='tb1'>";
  34.         echo "<td>".$prodid."</td>";
  35.         echo "<td>".$prodname."</td>";
  36.         echo "<td>".$categ."</td>";
  37.         echo "<td>".$qty."</td>";
  38.         echo "<td> <a href='edit.php?id=$prodid' id='popedit'>Update</a>  | <a href='delete.php?id=$prodid' id='popedit'>Delete</a>  | <a href='reserve.php?id=$prodid' id='popreserve'>Reserve</a>  </td>";
  39.         echo "</tr>";
  40. }
  41. ?>
  42. <tbody>
  43.                         </table>
  44.                 </div>
  45. </div>
  46. </body>
  47. </html>
And for the function of Updating the products.
  1. <?php
  2.     include "dbconnect.php";
  3.     $prod_id=$_GET['id'];
  4.     $q = "select * from tblproducts where prod_id='$prod_id'";
  5.     $result=mysql_query($q);
  6.     while($rs=mysql_fetch_array($result)){
  7.         $prodid=$rs['prod_id'];
  8.         $prodtitle=$rs['prod_name'];
  9.         $prodctry=$rs['prod_ctry'];
  10.         $prodqty=$rs['prod_qty'];
  11.     }
  12.     $fctgry="select * from category";
  13.     $result=mysql_query($fctgry);
  14. ?>
  15. <center><div id="header"><h1 class="header-text">Update, Delete & Reserve Products</h1><div id=menu-modal>
  16.         <a href="index.php"><button id="b1" class="btn btn-primary ">&nbspHome</button></a>
  17.         <a href="viewreserved.php"><button id="b2" class="btn btn-primary ">&nbspView Reserved Products</button></a>
  18. </div></div></center>
  19. <div id="container">
  20. <div class="form_head" align="center">Update Products</div><br>
  21.         <form method="post" action="process.php">
  22.                 <label class="control-label">Product ID :</label>
  23. <div class="controls">
  24.         <input type="text" name="ebookid" placeholder="Product ID" id="ebookid" value="<?php echo $prodid;?>"/>
  25. </div>
  26.                 <label class="control-label">Product Name :</label>
  27. <div class="controls">
  28.         <input type="text" name="ebookname" placeholder="Product Name" id="ebookname" value="<?php echo $prodtitle;?>"/>
  29. </div>
  30.                 <label class="control-label">Category :</label>
  31. <div class="controls">
  32. <select name="ecategory" id="ecategory">
  33.         <option><?php echo $prodctry; ?></option>
  34. <?php
  35.         while($rs=mysql_fetch_array($result)){
  36.         $categ=$rs['category'];
  37.         echo "<option>".$categ."</option>";
  38.         }
  39. ?>
  40. </select>
  41. </div>
  42.                 <label class="control-label">Quantity :</label>
  43. <div class="controls">
  44.         <input type="text" name="equantity" placeholder="Number of Products to add" id="equantity" value="<?php echo $prodqty; ?>"/>
  45. </div>
  46. <div class="controls">
  47.                 <button id="btn" class="btn btn-primary">Update</button>
  48.                 <a href="index.php" id="btnc" class="btn btn-info">Cancel</a>
  49. </div>
  50.         </form>
Result For the Delete function of every product that you select. In this function the data has been disable the Update function so the user can't rename or edit the fields in each data products.
  1. <?php
  2.     include "dbconnect.php";
  3.     $prod_id=$_GET['id'];
  4.     $q = "select * from tblproducts where prod_id='$prod_id'";
  5.     $result=mysql_query($q);
  6.     while($rs=mysql_fetch_array($result)){
  7.         $prodid=$rs['prod_id'];
  8.         $prodtitle=$rs['prod_name'];
  9.         $prodctry=$rs['prod_ctry'];
  10.         $prodqty=$rs['prod_qty'];
  11.     }
  12.     $fctgry="select * from category";
  13.     $result=mysql_query($fctgry);
  14. ?>
  15. <center><div id="header"><h1 class="header-text">Update, Delete & Reserve Products</h1><div id=menu-modal>
  16.         <a href="index.php"><button id="b1" class="btn btn-primary ">&nbspHome</button></a>
  17.         <a href="viewreserved.php"><button id="b2" class="btn btn-primary ">&nbspView Reserved Products</button></a>
  18. </div></div></center>
  19. <div id="container">
  20. <div class="form_head" align="center">Delete Products</div><br>
  21.         <form method="post" action="process.php?did=<?php echo $prodid; ?>">
  22.                 <label class="control-label">Product ID :</label>
  23. <div class="controls">
  24.         <input type="text" name="dbookid" placeholder="Product ID" id="dbookid" value="<?php echo $prodid;?>" disabled/>
  25. </div>
  26.                 <label class="control-label">Product Name :</label>
  27. <div class="controls">
  28.         <input type="text" name="dbookname" placeholder="Product Name" id="dbookname" value="<?php echo $prodtitle;?>" disabled/>
  29. </div>
  30.                 <label class="control-label">Category :</label>
  31. <div class="controls">
  32.         <select name="dcategory" id="dcategory" disabled>
  33.                 <option><?php echo $prodctry; ?></option>
  34. <?php
  35.         while($rs=mysql_fetch_array($result)){
  36.         $categ=$rs['category'];
  37.         echo "<option>".$categ."</option>";
  38. }
  39. ?>
  40.         </select>
  41. </div>
  42.                 <label class="control-label">Quantity :</label>
  43. <div class="controls">
  44.         <input type="text" name="dquantity" placeholder="Number of Products to add" id="dquantity" value="<?php echo $prodqty; ?>" disabled/>
  45. </div>
  46. <div class="controls">
  47.         <button id="btn" class="btn btn-primary">Delete</button>
  48.         <a href="index.php" id="btnc" class="btn btn-info">Cancel</a>
  49. </div>
  50.         </form>
  51. </div>
Result I hope that you learn in this tutorial and don't forget to Like and Share. Enjoy Coding! :)

Comments

Add new comment