Answer the question
In order to leave comments, you need to log in
Why is it not getting text from the database?
Does not display the text that is taken from the database. The connection is present, there are no errors in the requests, I checked it through print_r (), everything is filled.
Request code:
$u_r_name = $db->prepare('SELECT name FROM accounts WHERE mail="'.$_SESSION['mail'].'";');
$u_r_surname = $db->prepare('SELECT surname FROM accounts WHERE mail="'.$_SESSION['mail'].'";');
<? if(empty($_SESSION['pid'])): ?>
<div id="auth-block">
<a href="/login" class="login-btn nav-desktop-menu-header">Войти</a>
<a href="/registration" class="reg-btn nav-desktop-menu-header">Регистрация</a>
</div>
<? else: ?>
<div id="account-info-block">
<div class="dash-text" id="account-name"><? echo $u_r_name->execute() . ' ' . $u_r_surname->execute(); ?></div>
<hr class="hr-mini" />
</div>
<? endif; ?>
Answer the question
In order to leave comments, you need to log in
Horrible...
Or even so will I be at risk of sql injection?
$stmt = $db->prepare('SELECT name, surname FROM accounts WHERE mail=?');
$stmt->execute([$_SESSION['mail']]);
$user = $stmt->fetch();
<div class="dash-text" id="account-name"><?= $user['name'] . ' ' . $user['surname'] ?></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question