Jump to content

Recommended Posts

Hi guys

 

i want to know if you can put and if statement within an if statement....the reason i ask is because i have created my login screen, which works, but i now need to add in an if statement so that if the access_level is set to 1 they are direted to one page, to 2 then another and to 3 another...i have had a go at it but i got an error

 

$sql="SELECT * FROM customer WHERE uname='$n' AND pwd=MD5('$p')"; 
$query=mysql_query($sql) or die("Queryfailed:".mysql_error());
if (mysql_num_rows($query) != 0) { 
$row = mysql_fetch_assoc($query);
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['surname'] = $row['surname'];
$_SESSION['address1'] = $row['address1'];
$_SESSION['address2'] = $row['address2'];
$_SESSION['town'] = $row['town'];
$_SESSION['county'] = $row['county'];
$_SESSION['postcode'] = $row['postcode'];
$_SESSION['date_of_birth'] = $row['date_of_birth'];
$_SESSION['home_number'] = $row['home_number'];
$_SESSION['mobile_number'] = $row['mobile_number'];
$_SESSION['points'] = $row['points'];
$_SESSION['access_level'] = $row['access_level'];
$mytime=time();
$mytime=date("H:i:s A",$mytime);
$_SESSION['time'] = $mytime;
$_SESSION['status'] = 'logged';
$_SESSION['username'] = $n;

//header ("location:welcome.php");
if {
$_SESSION['access_level'] = '1';
header ("location:welcome1.php");
}
else if {
$_SESSION['access_level'] = '2';
header ("location:welcome2.php");
}
else if {
$_SESSION['access_level'] = '3';
header ("location:welcome3.php");
}
exit;
} else {
$_SESSION['status'] = 'not logged';
header("Location:Messages.php?msg=2" ); 
exit();
}
}

 

im gettin an - Parse error: parse error, unexpected '{', expecting '(' in C:\Program Files\xampp\htdocs\PBL\default.php on line 48

line 48 is the first if under the commented out header

 

any help is much appreciated

 

cheers

bhav

Link to comment
https://forums.phpfreaks.com/topic/38307-solved-if-question/
Share on other sites

ahh right i see waht you mean

 

i got it working using the following code

 

$sql="SELECT * FROM customer WHERE uname='$n' AND pwd=MD5('$p')"; 
$query=mysql_query($sql) or die("Queryfailed:".mysql_error());
if (mysql_num_rows($query) != 0) { 
$row = mysql_fetch_assoc($query);
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['surname'] = $row['surname'];
$_SESSION['address1'] = $row['address1'];
$_SESSION['address2'] = $row['address2'];
$_SESSION['town'] = $row['town'];
$_SESSION['county'] = $row['county'];
$_SESSION['postcode'] = $row['postcode'];
$_SESSION['date_of_birth'] = $row['date_of_birth'];
$_SESSION['home_number'] = $row['home_number'];
$_SESSION['mobile_number'] = $row['mobile_number'];
$_SESSION['points'] = $row['points'];
$_SESSION['access_level'] = $row['access_level'];
$mytime=time();
$mytime=date("H:i:s A",$mytime);
$_SESSION['time'] = $mytime;
$_SESSION['status'] = 'logged';
$_SESSION['username'] = $n;

if ($_SESSION['access_level'] == '1') {
header ("Location: http://localhost/PBL/welcome1.php");
}
elseif ($_SESSION['access_level'] == '2') {
header ("Location: http://localhost/PBL/welcome2.php");
}
elseif ($_SESSION['access_level'] == '3') {
header ("Location: http://localhost/PBL/welcome3.php");
exit;
}

} else {
$_SESSION['status'] = 'not logged';
header("Location:Messages.php?msg=2" ); 
exit();
}
}

Link to comment
https://forums.phpfreaks.com/topic/38307-solved-if-question/#findComment-183607
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.