Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Nutrition</title>
- </head>
- <body align=center>
- <?php
- #require_once("functions.php");
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "nutrition";
- $mysqli = new mysqli("$servername", "$username", "$password", "$dbname");
- if ($mysqli->connect_error)
- {
- die("Connection failed: " . $mysqli->connect_error);
- }
- #$stmt = $mysqli ->prepare("SELECT brand FROM food WHERE id=1;");
- #$stmt->bind_result($brand);
- #$stmt->execute();
- #while($stmt->fetch())
- #{
- # $nimi = $brand;
- # echo "<p>$nimi</p>";
- #}
- #$brand = "test";
- #$description = "test";
- #$calories = 744;
- #$carbs = 0.9;
- #$protein = 0.6;
- #$fat = 82;
- #$barcode = 4740153010001;
- #global $mysqli;
- #$stmt = $mysqli->prepare("INSERT INTO food(brand, description, calories, carbs, protein, fat, barcode) #VALUES(?, ?, ?, ?, ?, ?, ?)");
- #$stmt->bind_param("ssdddds", $brand, $description, $calories, $carbs, $protein, $fat, $barcode);
- #$stmt->execute();
- ?>
- <h1>Tere</h1>
- <div class="row">
- <div class=".col-md-4">
- <form>
- Brand:
- <input type="text" name="brand" placeholder="Alma"></input><br><br>
- Description:
- <input tpe="text" name="description" placeholder="Piim 2.5%"></input><br><br>
- Calories:
- <input tpe="text" name="calories" placeholder="55"></input><br><br>
- Carbs:
- <input tpe="text" name="carbs" placeholder="4.8"></input><br><br>
- Protein:
- <input tpe="text" name="protein" placeholder="3.2"></input><br><br>
- Fat:
- <input tpe="text" name="fat" placeholder="2.5"></input><br><br>
- Barcode
- <input tpe="text" name="barcode" placeholder="474012500410"></input><br><br>
- <input type="submit" value="Add food"></input>
- </form>
- <?php
- $brand = $_REQUEST["brand"];
- $description = $_REQUEST["description"];
- $calories = $_REQUEST["calories"];
- $carbs = $_REQUEST["carbs"];
- $protein = $_REQUEST["protein"];
- $fat = $_REQUEST["fat"];
- $barcode = $_REQUEST["barcode"];
- header("Location addFood.php?success");
- global $mysqli;
- $stmt = $mysqli->prepare("INSERT INTO food(brand, description, calories, carbs, protein, fat, barcode) VALUES(?, ?, ?, ?, ?, ?, ?)");
- $stmt->bind_param("ssdddds", $brand, $description, $calories, $carbs, $protein, $fat, $barcode);
- $stmt->execute();
- ?>
- </div>
- </div>
- <?php
- $stmt = $mysqli ->prepare("SELECT brand, description, calories, carbs, protein, fat, barcode FROM food");
- $stmt->bind_result($brand, $description, $calories, $carbs, $protein, $fat, $barcode);
- $stmt->execute();
- while($stmt->fetch())
- {
- $newbrand = $brand;
- $newdescription = $description;
- $newcalories = $calories;
- $newcarbs = $carbs;
- $newprotein = $protein;
- $newfat = $fat;
- $newbarcode = $barcode;
- echo "
- <table border='1' align=center border-collapse:collapse>
- <tr>
- <td>$newbrand</td>
- <td>$newdescription</td>
- <td>$newcalories</td>
- <td>$newcarbs</td>
- <td>$newprotein</td>
- <td>$newfat</td>
- <td>$newbarcode</td>
- </tr>
- </table>
- ";
- }
- $mysqli->close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement