I have a header script which runs some user check etc. One of those checks is his username his privileges and number of answers left.
this is that script called header.php
if(isset($_SESSION['activeUser']))
{
$activeUser=$_SESSION['activeUser'];
$activeUserName=$_SESSION['activeUserName'];
$activeUserType=$_SESSION['activeUserType'];
$activeUserId=$_SESSION['activeUserId'];
$odgovori=$_SESSION['preostaliOdgovori'];
}
if(isset($_SESSION['activeUser']))
{
echo "<div style='float: right;'>";
echo "<h3>Prijavljeni ste kao: ".$_SESSION['activeUser']."</h3>";
echo "<h3>Prava: ".$_SESSION['tipNaziv']."</h3>";
echo "<h3>Preostali odgovori: ".$odgovori."</h3>";
echo"</div>";
}
else
{
echo "<h3 style='float: right;'>Niste prijavljeni!</h3>";
}
So I want to read preostaliOdgovori from another script (preostaliOdgovori is table column) mojaTvrtka.php is a script where this is happening
$connect = connectDB();
$query ="SELECT pitanje.pitanje_id,naslov,pitanje.tvrtka_id, tvrtka.tvrtka_id,preostaliOdgovori ,
zaposlenik.tvrtka_id,korisnik_id
FROM pitanje
INNER JOIN tvrtka ON tvrtka.tvrtka_id = pitanje.tvrtka_id
INNER JOIN zaposlenik ON zaposlenik.tvrtka_id = pitanje.tvrtka_id
WHERE korisnik_id = '$activeUserId'";
if(isset($_SESSION['activeUser']))
{
$query1="SELECT tvrtka.tvrtka_id,preostaliOdgovori,zaposlenik.tvrtka_id,korisnik_id
FROM tvrtka
INNER JOIN zaposlenik ON zaposlenik.tvrtka_id = tvrtka.tvrtka_id
WHERE korisnik_id = '$activeUserId'";
$result2=queryDB($connect,$query1);
while($row=mysqli_fetch_array($result2))
{
$odgovori=$row['preostaliOdgovori'];
}
}
$_SESSION['preostaliOdgovori']=$odgovori;
All of this actually works but only when I manually load mojaTvrtka.php. I would like to make it that when a user logs in this number is automatically printed in header.php but all I get is undefined index. Im not sure what I am doing wrong.