Advertisement
Guest User

Untitled

a guest
Mar 18th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" href="styles.css">
  5. <title>Store product information</title>
  6. </head>
  7. <body>
  8.  
  9. <?php
  10.  
  11. $host = "localhost";
  12. $database = "shopDB";
  13. $username = "root";
  14. $password = "";
  15.  
  16. $conn = new mysqli($host, $username, $password);
  17. $db_handle = $conn->select_db($database);
  18.  
  19. if ($db_handle)
  20. {
  21. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  22. {
  23. // Upload to server
  24. $name = mysqli_real_escape_string($conn, $_POST['name']);
  25. $quantity = mysqli_real_escape_string($conn, $_POST['quantity']);
  26. $price = mysqli_real_escape_string($conn, $_POST['price']);
  27. $description = mysqli_real_escape_string($conn, $_POST['description']);
  28.  
  29. $insert_sql = "INSERT INTO products (name, quantity, price, description) VALUES ('$name', '$quantity', '$price', '$description')";
  30. $insert_result = $conn->query($insert_sql);
  31.  
  32. if ($insert_result)
  33. {
  34. // Uploaded successfully
  35. } else {
  36. print mysqli_error($conn);
  37. }
  38. }
  39.  
  40. $products_sql = "SELECT
  41. products.name,
  42. products.quantity,
  43. products.price,
  44. products.description
  45. FROM products";
  46. $products_result = $conn->query($products_sql);
  47.  
  48. if ($products_result)
  49. {
  50. print "<table id='products_table'>";
  51.  
  52. print "<thead>";
  53. print "<tr>";
  54. print "<th>Name</td>";
  55. print "<th>Quantity</td>";
  56. print "<th>Price</td>";
  57. print "<th>Description</td>";
  58. print "</tr>";
  59. print "</thead>";
  60.  
  61. print "<tbody>";
  62. while ($db_field = mysqli_fetch_assoc($products_result))
  63. {
  64. print "<tr>";
  65. print "<td>" . $db_field['name'] . "</td>";
  66.  
  67. if ($db_field['quantity'] == '0') {
  68. print "<td class='out_of_stock_cell'>" . $db_field['quantity'] . "</td>";
  69. } else {
  70. print "<td>" . $db_field['quantity'] . "</td>";
  71. }
  72.  
  73. print "<td>" . $db_field['price'] . "</td>";
  74. print "<td>" . $db_field['description'] . "</td>";
  75. print "<tr>";
  76. }
  77. print "</tbody>";
  78. print "</table>";
  79. }
  80. }
  81.  
  82. ?>
  83.  
  84. <h3 id="insert_items_header">Insert items</h3>
  85. <form action="index.php" method="post">
  86. <table>
  87. <thead>
  88. <th>Name</th>
  89. <th>Quantity</th>
  90. <th>Price</th>
  91. <th>Description</th>
  92. </thead>
  93. <tbody>
  94. <td><input name="name" type="text"></input></td>
  95. <td><input name="quantity" type="text"></input></td>
  96. <td><input name="price" type="text"></input></td>
  97. <td><input name="description" type="text"></input></td>
  98. </tbody>
  99. </table>
  100. <br>
  101. <input id="submit_button" type="submit" value="Register item">
  102. </form>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement