For a long time I have been trying to solve one problem. After the user logs in, the php script retrieves all information from its mysql line.
...
if ($rezultat = @$polaczenie->query(
sprintf("SELECT * FROM kontabankowe WHERE login = '%s' AND haslo = '%s'",
mysqli_real_escape_string($polaczenie, $login),
mysqli_real_escape_string($polaczenie, $haslo)))) {
$ilu_userow = $rezultat->num_rows;
if ($ilu_userow > 0) {
$_SESSION['zalogowany'] = true;
$wiersz = $rezultat->fetch_assoc();
$_SESSION['id'] = $wiersz['id'];
$_SESSION['imie'] = $wiersz['imie'];
$_SESSION['nazwisko'] = $wiersz['nazwisko'];
$_SESSION['login'] = $wiersz['login'];
$_SESSION['haslo'] = $wiersz['haslo'];
$_SESSION['nrkonta'] = $wiersz['nrkonta'];
$_SESSION['pieniadze'] = $wiersz['pieniadze'];
$rezultat->free_result();
...
Then, I display this data in my application, in this way:
<div id="pieniadze">
<span>Dostępne środki: <?php echo $_SESSION['pieniadze'] ?></span> PLN
</div>
But in later actions in the application, the value $_SESSION['pieniadze']
in mysql changes to a different value, but in the above place, the previous value is displayed.
In my opinion, in the place where I update this value, it should re-download the value of mysql and convert it to a variable $_SESSION['pieniadze']
, but I do not know how to do it. maybe there are better solutions?
If you want the values to be updated, do the MYSQL query at each time, so it will refresh the value. It will impact a bit in performance, but is the only way.
So you might save the user id in a session variable and then retrieve the rest of the data in all requests.
Session variables store information in PHP for the user, MYSQL is not directly involved.
have you assigned the following values? of the kind
$ login = $ _POST ['login']; >
$ haslo = $ _POST ['haslo'];
if you did it check with if possible result exists with an 'echo'
if ($ ilu_userow> 0) {
echo 'exist'
....