Advertisement
Guest User

Untitled

a guest
May 11th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Nutrition</title>
  6. </head>
  7. <body align=center>
  8. <?php
  9. #require_once("functions.php");
  10.  
  11. $servername = "localhost";
  12. $username = "root";
  13. $password = "";
  14. $dbname = "nutrition";
  15.  
  16. $mysqli = new mysqli("$servername", "$username", "$password", "$dbname");
  17. if ($mysqli->connect_error)
  18. {
  19. die("Connection failed: " . $mysqli->connect_error);
  20. }
  21. #$stmt = $mysqli ->prepare("SELECT brand FROM food WHERE id=1;");
  22. #$stmt->bind_result($brand);
  23. #$stmt->execute();
  24.  
  25. #while($stmt->fetch())
  26. #{
  27. # $nimi = $brand;
  28. # echo "<p>$nimi</p>";
  29. #}
  30.  
  31. #$brand = "test";
  32. #$description = "test";
  33. #$calories = 744;
  34. #$carbs = 0.9;
  35. #$protein = 0.6;
  36. #$fat = 82;
  37. #$barcode = 4740153010001;
  38.  
  39. #global $mysqli;
  40. #$stmt = $mysqli->prepare("INSERT INTO food(brand, description, calories, carbs, protein, fat, barcode) #VALUES(?, ?, ?, ?, ?, ?, ?)");
  41. #$stmt->bind_param("ssdddds", $brand, $description, $calories, $carbs, $protein, $fat, $barcode);
  42. #$stmt->execute();
  43.  
  44.  
  45. ?>
  46. <h1>Tere</h1>
  47. <div class="row">
  48. <div class=".col-md-4">
  49. <form>
  50. Brand:
  51. <input type="text" name="brand" placeholder="Alma"></input><br><br>
  52. Description:
  53. <input tpe="text" name="description" placeholder="Piim 2.5%"></input><br><br>
  54. Calories:
  55. <input tpe="text" name="calories" placeholder="55"></input><br><br>
  56. Carbs:
  57. <input tpe="text" name="carbs" placeholder="4.8"></input><br><br>
  58. Protein:
  59. <input tpe="text" name="protein" placeholder="3.2"></input><br><br>
  60. Fat:
  61. <input tpe="text" name="fat" placeholder="2.5"></input><br><br>
  62. Barcode
  63. <input tpe="text" name="barcode" placeholder="474012500410"></input><br><br>
  64. <input type="submit" value="Add food"></input>
  65. </form>
  66. <?php
  67. $brand = $_REQUEST["brand"];
  68. $description = $_REQUEST["description"];
  69. $calories = $_REQUEST["calories"];
  70. $carbs = $_REQUEST["carbs"];
  71. $protein = $_REQUEST["protein"];
  72. $fat = $_REQUEST["fat"];
  73. $barcode = $_REQUEST["barcode"];
  74. header("Location addFood.php?success");
  75. global $mysqli;
  76. $stmt = $mysqli->prepare("INSERT INTO food(brand, description, calories, carbs, protein, fat, barcode) VALUES(?, ?, ?, ?, ?, ?, ?)");
  77. $stmt->bind_param("ssdddds", $brand, $description, $calories, $carbs, $protein, $fat, $barcode);
  78. $stmt->execute();
  79. ?>
  80. </div>
  81. </div>
  82. <?php
  83. $stmt = $mysqli ->prepare("SELECT brand, description, calories, carbs, protein, fat, barcode FROM food");
  84. $stmt->bind_result($brand, $description, $calories, $carbs, $protein, $fat, $barcode);
  85. $stmt->execute();
  86.  
  87. while($stmt->fetch())
  88. {
  89. $newbrand = $brand;
  90. $newdescription = $description;
  91. $newcalories = $calories;
  92. $newcarbs = $carbs;
  93. $newprotein = $protein;
  94. $newfat = $fat;
  95. $newbarcode = $barcode;
  96. echo "
  97. <table border='1' align=center border-collapse:collapse>
  98. <tr>
  99. <td>$newbrand</td>
  100. <td>$newdescription</td>
  101. <td>$newcalories</td>
  102. <td>$newcarbs</td>
  103. <td>$newprotein</td>
  104. <td>$newfat</td>
  105. <td>$newbarcode</td>
  106.  
  107.  
  108. </tr>
  109. </table>
  110.  
  111.  
  112. ";
  113. }
  114. $mysqli->close();
  115. ?>
  116.  
  117. </body>
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement