[Solved] Update the Session value from database [closed]


If I understood the question correctly you want to read a value from a Database.

I assume, you have got an id, stored in $_SESSION[‘Auth’][‘ID’], that provides the User ID of the user in the Database.

First you request your new Value from the Database (Notice that I need to know the ID of the user), then you store it in the Session structure.
(If you are not familiar with the Database querying in PHP look at the PHP MySQLi Extension)

$stmt = $mysqli->prepare("SELECT currency FROM user WHERE id=? LIMIT 1");
$stmt->bind_param ('i', $_SESSION['Auth']['ID']);
$stmt->execute();
$stmt->bind_result($id);
if ($stmt->fetch()) {
    $_SESSION['Auth']['User']['Currency'] = $id;
}

Like you have seen, i did not need to unset the Session value before storing it. Just make shure, you have session_start at the beginning.

solved Update the Session value from database [closed]