<?php
$res = mysql_query("SELECT * FROM users WHERE username = '$user' LIMIT 1");
if(mysql_num_rows($res)>0){
   $d = mysql_fetch_array($res)){
      if($pass == $d['password']){
         session_regenerate_id(); //security for changing permissions
         $_SESSION['user_id'] = $d['user_id'];
         $_SESSION['usertype_id'] = $d['usertype_id'];
         switch($d['usertype_id']){
            case 1:
               $loc = "nurse.php";
               break;
            case 2:
               $loc = "paramedic.php";
               break;
            case 3:
               $loc = "doctor.php";
               break;
            case 4:
               $loc = "medprac.php";
               break;
            case 5:
               $loc = "wardboss.php";
               break;
            case 6:
               $loc = "consultant.php";
               break;
         }
         header("Location: $loc");
      }
   }
}
?>

What is the problem ?

It complain error in line 4, and ) is remove it complain { in line 5 and if removed it will complain line 6 syntax error.

Your parenthesis don't line up.

$res = mysql_query("SELECT * FROM users WHERE username = '$user' LIMIT 1");
if(mysql_num_rows($res)>0){
$d = mysql_fetch_array($res)){
if($pass == $d['password']){
session_regenerate_id(); //security for changing permissions
$_SESSION['user_id'] = $d['user_id'];
$_SESSION['usertype_id'] = $d['usertype_id'];
switch($d['usertype_id']){
case 1:
$loc = "nurse.php";
break;
case 2:
$loc = "paramedic.php";
break;
case 3:
$loc = "doctor.php";
break;
case 4:
$loc = "medprac.php";
break;
case 5:
$loc = "wardboss.php";
break;
case 6:
$loc = "consultant.php";
break;
}
header("Location: $loc");
}
}
}
?>

Can you please help?

You had an exstra ) on line 3

long live 'TAB'

<?php
 $res = mysql_query("SELECT * FROM users WHERE username = '$user' LIMIT 1");
if(mysql_num_rows($res)>0)
	{
	$d = mysql_fetch_array($res);	
	if($pass == $d['password'])
		{
		session_regenerate_id(); //security for changing permissions
		$_SESSION['user_id'] = $d['user_id'];
		$_SESSION['usertype_id'] = $d['usertype_id'];
		switch($d['usertype_id'])
			{
			case 1:
				$loc = "nurse.php";
				break;
			case 2:
				$loc = "paramedic.php";
				break;
			case 3:
				$loc = "doctor.php";
				break;
			case 4:
				$loc = "medprac.php";
				break;
			case 5:
				$loc = "wardboss.php";
				break;
			case 6:
				$loc = "consultant.php";
				break;
			}
		header("Location: $loc");
		}
	}
?>

Please help in correcting if after you must have runned it

You had an exstra ) on line 3

long live 'TAB'

<?php
 $res = mysql_query("SELECT * FROM users WHERE username = '$user' LIMIT 1");
if(mysql_num_rows($res)>0)
	{
	$d = mysql_fetch_array($res);	
	if($pass == $d['password'])
		{
		session_regenerate_id(); //security for changing permissions
		$_SESSION['user_id'] = $d['user_id'];
		$_SESSION['usertype_id'] = $d['usertype_id'];
		switch($d['usertype_id'])
			{
			case 1:
				$loc = "nurse.php";
				break;
			case 2:
				$loc = "paramedic.php";
				break;
			case 3:
				$loc = "doctor.php";
				break;
			case 4:
				$loc = "medprac.php";
				break;
			case 5:
				$loc = "wardboss.php";
				break;
			case 6:
				$loc = "consultant.php";
				break;
			}
		header("Location: $loc");
		}
	}
?>

Show a little effort. pzuurveen already corrected it. There was no need to run it to see those mistakes.

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.