会话不会显示新值

发布于 2025-01-12 02:06:00 字数 4359 浏览 0 评论 0原文

我一直在尝试获取会话更新,我也使用 mysql 创建了基本更新,它在 sql 数据库中更新,但不会在页面内显示更改。 我不知道还要检查什么,因为我检查了 chrome 设置,它确实显示了 php 会话 id 值,但如果我进入会话存储,它什么也没有显示。 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();
}

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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文