I'm working on a project that involves writing PHP code into a database. I've created the appropriate database through PHP MyAdmin ( The database looks like this)
In order to write to this database, I have created a HTML and PHP file. The HTML code:
<h1> <u> Enter Food </u> </h1>
<form name="enter_food" action="enter_food_script.php" method="post">
Choose Quantity:
<input type="text" name="number" size = "5">
<select name="serving_size">
<option value = "plate"> Plate </option>
<option value = "bowl"> Bowl </option>
<option value = "cup"> Cup </option>
</select>
<br>
Choose Turkish Food:
<select name="turk_food">
<option value = "manti"> Manti </option>
<option value = "kofta"> Kofta </option>
<option value = "simit"> Simit </option>
</select>
<br>
<br> <button type="non-turk_food"><a href="/IA/non-turkish_food.php">Enter non-Turkish food</a></button> <br>
<br> <input type="submit" value="Submit"> <br>
<br> <button type="homepage"><a href="/IA/Homepage.php">Return to Homepage</a></button> <br> <br>
</form>
The PHP code:
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "turkish_calorie_tracker";
$conn = new mysqli($servername, $username, $password, $dbname);
if($conn->connect_error){
die("Connection failed:" . $conn->connect_error ."; Please contact the creator of this app.");
}
date_default_timezone_set('Asia/Dubai'); $date = date('Y/m/s h:i:s a', time());
$food = $_POST['turk_food'];
$quantity = $_POST['number'] . $_POST['serving_size'];
$consumed = "Consumed";
$calories = 100;
$entry = $conn->prepare("INSERT INTO data(Food/Exercise, Quantity, Calories Burned or Consumed, Number of Calories) VALUES ( ?,?,?,?)");
$entry->bind_param("sssi", $food, $quantity, $consumed, $calories);
$entry->execute();
if($entry){
echo 'Inserted';
} else {
echo 'Not Inserted';
}
$entry->close();
header("refresh:1.5; url=/ia/enter_food.html");
$conn->close();
Can someone please help me by saying the error in my code?