Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="styles.css">
- <title>Store product information</title>
- </head>
- <body>
- <?php
- $host = "localhost";
- $database = "shopDB";
- $username = "root";
- $password = "";
- $conn = new mysqli($host, $username, $password);
- $db_handle = $conn->select_db($database);
- if ($db_handle)
- {
- if ($_SERVER['REQUEST_METHOD'] == 'POST')
- {
- // Upload to server
- $name = mysqli_real_escape_string($conn, $_POST['name']);
- $quantity = mysqli_real_escape_string($conn, $_POST['quantity']);
- $price = mysqli_real_escape_string($conn, $_POST['price']);
- $description = mysqli_real_escape_string($conn, $_POST['description']);
- $insert_sql = "INSERT INTO products (name, quantity, price, description) VALUES ('$name', '$quantity', '$price', '$description')";
- $insert_result = $conn->query($insert_sql);
- if ($insert_result)
- {
- // Uploaded successfully
- } else {
- print mysqli_error($conn);
- }
- }
- $products_sql = "SELECT
- products.name,
- products.quantity,
- products.price,
- products.description
- FROM products";
- $products_result = $conn->query($products_sql);
- if ($products_result)
- {
- print "<table id='products_table'>";
- print "<thead>";
- print "<tr>";
- print "<th>Name</td>";
- print "<th>Quantity</td>";
- print "<th>Price</td>";
- print "<th>Description</td>";
- print "</tr>";
- print "</thead>";
- print "<tbody>";
- while ($db_field = mysqli_fetch_assoc($products_result))
- {
- print "<tr>";
- print "<td>" . $db_field['name'] . "</td>";
- if ($db_field['quantity'] == '0') {
- print "<td class='out_of_stock_cell'>" . $db_field['quantity'] . "</td>";
- } else {
- print "<td>" . $db_field['quantity'] . "</td>";
- }
- print "<td>" . $db_field['price'] . "</td>";
- print "<td>" . $db_field['description'] . "</td>";
- print "<tr>";
- }
- print "</tbody>";
- print "</table>";
- }
- }
- ?>
- <h3 id="insert_items_header">Insert items</h3>
- <form action="index.php" method="post">
- <table>
- <thead>
- <th>Name</th>
- <th>Quantity</th>
- <th>Price</th>
- <th>Description</th>
- </thead>
- <tbody>
- <td><input name="name" type="text"></input></td>
- <td><input name="quantity" type="text"></input></td>
- <td><input name="price" type="text"></input></td>
- <td><input name="description" type="text"></input></td>
- </tbody>
- </table>
- <br>
- <input id="submit_button" type="submit" value="Register item">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement