Hi All,

I havefollowing code and getting error "Parse error: syntax error, unexpected 'elseif' (T_ELSEIF) in C:\xampp\htdocs\SMR\index.php on line 13". Wehen i remove elseif and keep only if it just checks the first condition and ignor the second. When i put back elseif i get error. Please to fix this issue.

<?php
session_start();
error_reporting(0);
include('includes/dbconnection.php');

if(isset($_POST['login']))
  {
    $adminuser=$_POST['username'];
    $password=md5($_POST['password']);
    $userlvl=$_POST['userlvl'];
    $query=mysqli_query($con,"select ID from tbladmin where  UserName='$adminuser' && Password='$password' && userlvl='$userlvl' ");
    $ret=mysqli_fetch_array($query);
    elseif($ret>0 || userlvl==1){
     $_SESSION['cvmsaid']=$ret['ID'];
     header('location:dashboard.php');
    }
elseif($ret>0 || userlvl==2){
    $_SESSION['cvmsaid']=$ret['ID'];
     header('location:dashboard-supp.php');
    }

    else{
    $msg="Invalid Details.";
    }
  }
 ?>

I see an if on like 6, then an unmatched elseif on line 13. The matching elseif for line 6 seems to be on line 17.

So I agree that this should fail.

Hi @rproffitt

Thanks for the reply can you please help to rectify this code, I am new in PHP i followed the standard syntax referred on php documentation.

Kind Regards,
Naveed.

Sorry Naveed,

I can't correct your code because I don't know the intent. Try this: Make a copy and paste it into another file. Now delete all the code that doesn't have if, else and elseif. Here that shows the mismatched if and more.

Looks like the elseif on line 13 should be an if

Only strange thing is that $ret is an array, so I do not understand why you check for $ret > 0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.