I am relatively new to php. In the following code, I am trying to UPDATE the users 'dietID' (their current diet, of which they selected when they registered) so that it changes their dietID stored in the users database. However upon pressing the 'Change' submit button, nothing happens and nothing gets updated. Can anybody understand why?
Form processing code:
<?php
if(trim($_POST['submit']) == "Change") {
require_once("connect.php");
if (!$db_server) {
die("Unable to connect to MySQL: " . mysqli_connect_error($db_server));
} else {
mysqli_select_db($db_server, $db_database) or die("<h1>Couldn't find db</h1>");
//UPDATE records of users table
$query="UPDATE users SET dietID=".$dietopt." WHERE ID= $sess_userID";
mysqli_query($db_server, $query) or die("Update failed" . mysqli_error($db_server));
}
require_once("db_close.php");
} else {
$message= "Your diet has been updated";
}
?>
Form:
Would you like to change what your current diet is? Please select one
<br>
<form action="account.php" method="post">
<td><input type="radio" name="dietopt" value="Meat-eater"/>Meat-eater</td>
<tr>
<td><input type="radio" name="dietopt" value="Vegetarian"/>Vegetarian</td></tr>
<tr>
<td><input type="radio" name="dietopt" value="Vegan"/>Vegan</td></tr>
<br>
<input type="submit" name="Change" value="Change">
<br>
</form>
and the session variable created on the register page (not in any format, copy and pasted from snippets of the entire code of the register page):
$dietopt = $row['dietID'];
$_SESSION['diet'] = $dietopt;
$dietopt= trim($_POST['dietopt']);