I want to make the html element
<p id="userInfo"></p>
have the value of the username that was user to login in the session. I have the following variable set to contain the variable that holds the username and works this works for logging in.
$_SESSION['globalUser'] = $_POST['resultUser'];
I currently am attempting to set the userInfo element with
<script>document.getElementById(userInfo).value='<?php echo $_SESSION['globalUser']?>'</script>
This script is causing the error "Uncaught SyntaxError: Invalid or unexpected token"
When I open the developer tools and click the error it shows
<script>document.getElementById(userInfo).value='<br />
I also using the following statement to transfer the session across pages
<?php $session_value=(isset($_SESSION['id']))?$_SESSION['id']:''; ?>
What am I doing wrong here?
EDIT:
This is currently my query
$sqlUser = "SELECT `teacher_username` FROM `teacher` WHERE `teacher_username`='$user'";
$sqlPass = "SELECT `password` FROM `teacher` WHERE `password`='$pass'";
$resultUser = mysqli_query($connection, $sqlUser);
$resultPass = mysqli_query($connection, $sqlPass);
$textUser = $resultUser->fetch_assoc();
$textPass = $resultPass->fetch_assoc();
$_SESSION['globalUser'] = $_POST[$textUser['teacher_username']];
` in `$_SESSION['globalUser']`. – Barmar Nov 01 '18 at 00:49
` elements don't have a value, that's only for user input elements. You need to assign to `innerText`.
– Barmar Nov 01 '18 at 00:54