Dinar Dinar - 1 month ago 12
PHP Question

how to show message welcome to 'user log in' in php?

i have got Undefined Index : nmguru.

this is the code and i want to show welcome with name user logged in

<?php
if($_SESSION['typelog']="guru"){
echo "-==Welcome ".$_SESSION['nmguru']."==-"; }
else if($_SESSION['typelog']="admin"){
echo "-== Welcome Admin ==-"; }
else {
echo "<b>Selamat Datang di Website Sistem Informasi Akademik</b>";
}
?>

Answer

You are setting the $_SESSION['typelog'] value to "guru" by using only one equals, replace it with this:

if($_SESSION['typelog']=="guru"){

The same applies here, you need to replace the single = :

else if($_SESSION['typelog']=="admin"){

So the complete code should be:

if($_SESSION['typelog'] == "guru"){
   echo "-==Welcome ".$_SESSION['nmguru']."==-"; 
}elseif($_SESSION['typelog'] == "admin"){
   echo "-== Welcome Admin ==-"; 
}else {
   echo "<b>Selamat Datang di Website Sistem Informasi Akademik</b>";
}