SHARE
TWEET

Untitled

joyfriend Nov 19th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>
  4. Lab 12
  5. </title>
  6. </head>
  7. <body>
  8.  
  9.  
  10. <H1>Please provide the information about your product:</h1>
  11. <form action="<?php $_SERVER['PHP_SELF'];?>" method="get">
  12. Product's name:<input type="text" name="name"> <font color=red>*</font><br/><br/>
  13. Product's maker:<input type="text" name="maker"><br/><br/>
  14. Product's amount:<input type="text" name="amount"><br/><br/>
  15. Product's price:<input type="text" name="price"><br/><br/>
  16. <input type="submit" value="Add Record" name="add">
  17. <input type="submit" value="Find the Item with the Highest Price" name="highest">
  18. <input type="submit" value="Display All" name="displayAll"><br/><br/>
  19. <input type="submit" value="Group by Maker" name="groupByMaker">
  20. <input type="submit" value="Sort Items by Amount Descendly" name="sort">
  21. <input type="submit" value="Find the Average Price of all items" name="average"><br/><br/>
  22. <input type="submit" value="Delete Record by ID" name="delete"> ID to remove: <input type="text" name="id"><br/><br/>
  23. <input type="submit" value="Show by Maker" name="showByMaker"> Maker: <input type="text" name="maker2show"><br/><br/>
  24. </form>
  25. <hr/>
  26.  
  27. <?php
  28.  
  29. require_once("my_DB_functions.php");
  30.  
  31. $conn = My_Connect_DB();
  32.  
  33. // ADD RECORD
  34.  
  35. if ($_GET["add"])
  36. {
  37.     if (!empty($_GET["name"]))
  38.     {
  39.         $sql = "INSERT INTO Products (name, maker, amount, price) VALUES('".$_GET['name']."', '".$_GET['maker']."', '".$_GET['amount']."', '".$_GET['price']."');";
  40.         Run_SQL_Show_Table($conn, $sql, "Products");
  41.     }
  42.     else
  43.         echo "Product's name cannot be empty! Please try again.";
  44. }
  45. //  ITEM WITH HIGHEST PRICE
  46.  
  47. if ($_GET["highest"])
  48. {
  49.     $sql = "SELECT name, maker, amount, price FROM Products WHERE price
  50.         IN (SELECT MAX(price) FROM Products)";
  51.     Run_Select_Show_Table($conn, $sql);
  52. }
  53.  
  54. // DISPLAY ALL PRODUCTS
  55.  
  56. if ($_GET["displayAll"])
  57. {
  58.     $sql = "SELECT * FROM Products;";
  59.     Run_Select_Show_Table($conn, $sql);
  60. }
  61.  
  62. // GROUP BY MAKER
  63.  
  64. if ($_GET["groupByMaker"])
  65. {
  66.     $sql = "SELECT maker, SUM(amount) AS 'TotalItems'
  67.             FROM Products GROUP BY maker ORDER BY TotalItems DESC;";
  68.     Run_Select_Show_Table($conn, $sql);
  69. }
  70.  
  71. // SORT ITEMS DESC
  72.  
  73. if ($_GET["sort"])
  74. {
  75.     $sql = "SELECT * FROM Products ORDER BY amount DESC;";
  76.     Run_Select_Show_Table($conn, $sql);
  77. }
  78.  
  79. // AVERAGE PRICE
  80.  
  81. if ($_GET["average"])
  82. {
  83.     $sql = "SELECT AVG(price) AS 'Average price of all products' FROM Products;";
  84.     Run_Select_Show_Table($conn, $sql);
  85. }
  86.  
  87. // DELETE
  88.  
  89. if ($_GET["delete"])
  90. {
  91.     $sql = "DELETE FROM Products WHERE id = '".$_GET['id']."';";
  92.     Run_SQL_Show_Table($conn, $sql, "Products");
  93. }
  94.  
  95. // SHOW BY MAKER
  96.  
  97. if ($_GET["showByMaker"])
  98. {
  99.     $sql = "SELECT name, maker, amount, price FROM Products WHERE maker='".$_GET['maker2show']."';";
  100.     Run_Select_Show_Table($conn, $sql);
  101. }
  102.  
  103. mysqli_close();
  104.  
  105.  
  106.  
  107. ?>
  108. </body>
  109. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top