'Session will not show new values

I have been trying to get my session update, I have created a basic update with mysql as well, it updates in the sql database but it will not show the change within the page. I'm not sure what else to check, because I checked within the chrome settings and it does show a php session id value but if I go into session storage it shows nothing. transaction.php

<?php
$_title = 'Update profile';
require_once(__DIR__.'../../components/header.php');
session_start();
if(! isset($_SESSION['user_name'])){
    header('Location: ../sign_in/sign_in.php');
    die();
}
if (!isset($_SESSION["lang"])) { $_SESSION["lang"] = "en"; }
if (isset($_POST["lang"])) { $_SESSION["lang"] = $_POST["lang"]; }


require_once(__DIR__.'../../globals.php');
require_once(__DIR__.'../../db.php');

try{
    $db = _db();
}catch(Exception $ex){
    _res(500, ['info'=>'System under maintainance','error'=>__LINE__]);
}

$userProduct = $_SESSION['user']['user_id'];

$q = $db->prepare('SELECT * FROM users WHERE user_id = :userID');
$q->bindValue(":userID", $userProduct);

$q->execute();
require "../lan/lang." . $_SESSION["lang"] . ".php";

?>



<form class="style_form" id="update_profile" onsubmit="return false">

<div>
        <label for="name"><?=$_TXT[63]?></label>
        <input type="text" name="name" value="<?php echo $_SESSION['user']['user_name']?>">
    </div>
    <div>
        <label for="last_name"><?=$_TXT[64]?></label>
        <input type="text" name="last_name" value="<?php echo $_SESSION['user']['lastName']?>">
    </div>
    <div>
    <label for="email"><?=$_TXT[65]?></label>
      <input name="email" value="<?php echo $_SESSION['user']['email']?>" type="text">

<input type="hidden" name="userId" value="<?php echo $_SESSION['user']['user_id'] ?>">

  <button onclick="update()" id="updateButton"><?=$_TXT[60]?></button>  

    
</form>
</section>


<?php
require_once(__DIR__.'../../components/footer.php');
?>

api-transaction.php

<?php 
require_once(__DIR__.'../../globals.php');
// Validate name
if( ! isset( $_POST['name'] ) ){ _res(400,['name is required']); }
if( strlen( $_POST['name'] ) < _FRIST_NAME_MIN_LEN ){ _res(400,['name min '._FRIST_NAME_MIN_LEN.' characters']); }
if( strlen( $_POST['name'] ) > _FRIST_NAME_MAX_LEN ){ _res(400,['name max '._FRIST_NAME_MAX_LEN.' characters']); }

// Validate last_name
if( ! isset( $_POST['last_name'] ) ){ _res(400,['last_name is required']); }
if( strlen( $_POST['last_name'] ) < _LAST_NAME_MIN_LEN ){ _res(400,['last_name min '._LAST_NAME_MIN_LEN.' characters']); }
if( strlen( $_POST['last_name'] ) > _LAST_NAME_MAX_LEN ){ _res(400,['last_name max '._LAST_NAME_MAX_LEN.' characters']); }

// Validate email
if( ! isset( $_POST['email'] ) ){ _res(400,['email is required']); }
if( ! filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL ) ){ _res(400,['email is invalid']); }

$db = require_once(__DIR__.'../../db.php');
try{
    session_start();
    // $userid = $_SESSION['userId'];
    // $userid = $_SESSION['user']['user_id'];
    $userid = $_POST['userId'];


    $db->beginTransaction();

    //Change name
    $q = $db->prepare('UPDATE users SET user_name = :update_Name WHERE user_id = :userid');
    $q->bindValue(':userid',$userid);
    $q->bindValue(':update_Name', $_POST['name']);
    $q->execute();

    //Change last name
    $q = $db->prepare('UPDATE users SET lastName = :update_lastName WHERE user_id = :userid');
    $q->bindValue(':userid',$userid);
    $q->bindValue(':update_lastName', $_POST['last_name']);
    $q->execute();

    //change email
    $q = $db->prepare('UPDATE users SET email = :update_email WHERE user_id = :userid');
    $q->bindValue(':userid',$userid);
    $q->bindValue(':update_email', $_POST['email']);
    $q->execute();

    // change phone number 
    $q = $db->prepare('UPDATE users SET phone_number = :update_phone WHERE user_id = :userid');
    $q->bindValue(':userid',$userid);
    $q->bindValue(':update_phone', $_POST['phone_number']);
    $q->execute();

    $db->commit(); 
    header('Content-Type: application/json');
    $response = ["info" => "info has been updated"];
    echo json_encode($response);

    


}catch(Exception $ex){
    http_response_code(500);
    echo $ex;
    echo 'System under maintainance';
    exit();
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source