I have a form that show the user information and when I load userpage.php all info appear in each field and user can edit his information all is good until the user click on save button, it have to show the same form with updated information, data updated in database but the new data doesn't appear when user click save.
This is the form fields values after click on save button:
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\server\userpage.php on line 27
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\server\userpage.php on line 28
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\server\userpage.php on line 29
This is the userpage.php file:
<?php
session_start();
include 'connection.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Account</title>
</head>
<body>
<?php
if(isset($_SESSION['Status'])){
echo "<h2>".$_SESSION['Status']."<h2>";
unset($_SESSION['Status']);
}
$id = $_POST['loginID'];//a get this from login page
$_SESSION['nid'] = $id; //To use it in update file
$query = "SELECT id, username, phone, email FROM user WHERE id ='$id';";
$result = mysqli_query($conn,$query);
$info =mysqli_fetch_array($result);
?>
<form id="profile" action="update.php" method="post">
<fieldset>
<input type="text" name="username" id="username" value="<?php echo $info['username'] ?>" >
<input type="tel" name="phone" id="phone" value="<?php echo $info['phone'] ?>" >
<input type="email" name="email" id="email" value="<?php echo $info['email'] ?>">
<input class="button" type="submit" name="save" value="save">
</fieldset>
</form>
</body>
</html>
Update.php file code:
<?php
session_start();
include 'connection.php';
if(isset($_POST['save'])){
$id = $_SESSION['nid']; //Get the id from userpage.php file
$phone = $_POST['phone'];
$email = $_POST['email'];
$query = "UPDATE user SET phone='$phone', email='$email' WHERE id='$id'";
$result = mysqli_query($conn,$query);
if($result){
$_SESSION['Status'] = "Updated";
header('location: userpage.php');
}
else{
$_SESSION['Status'] = "Not updated";
header('location: userpage.php');
}
}
?>