-2

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>";
   } 
   ?>
Dinar
  • 1
  • 3
  • You're assigning, not comparing. To compare two values, you need to use double equality `if ($_SESSION['typelog'] == "guru") {` – Qirel Oct 22 '16 at 20:14
  • still not working and now unidentified variables after adding == – Dinar Oct 22 '16 at 20:18

1 Answers1

0

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>";
} 
useyourillusiontoo
  • 1,287
  • 1
  • 10
  • 24