bhavin_85 Posted February 13, 2007 Share Posted February 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/38307-solved-if-question/ Share on other sites More sharing options...
kenrbnsn Posted February 13, 2007 Share Posted February 13, 2007 Yes, you can nest if statements, but you didn't put a condition on those nested "if" statements, that's why you got the error. Ken Quote Link to comment https://forums.phpfreaks.com/topic/38307-solved-if-question/#findComment-183577 Share on other sites More sharing options...
Snooble Posted February 13, 2007 Share Posted February 13, 2007 might be better for you to use the switch statement also... Just a tip. Snooble Quote Link to comment https://forums.phpfreaks.com/topic/38307-solved-if-question/#findComment-183588 Share on other sites More sharing options...
bhavin_85 Posted February 13, 2007 Author Share Posted February 13, 2007 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(); } } Quote Link to comment https://forums.phpfreaks.com/topic/38307-solved-if-question/#findComment-183607 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.