Seitan Posted December 8, 2006 Share Posted December 8, 2006 Alright, I need help with an if statement, I'm trying to add an admin link to my page, but only for users who have specific user id's....this is what I have so far[code]if ($_SESSION['user_id'] == '1' OR '2') { echo '<a href="../php/admin.php">Admin</a>'; }[/code]unfortunately the admin link shows up for everyone, so what am I doing wrong Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 8, 2006 Share Posted December 8, 2006 The correct format of the "if" is[code]<?phpif ($_SESSION['user_id'] == '1' || $_SESSION['user_id'] == '2') echo '<a href="../php/admin.php">Admin</a>';?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 8, 2006 Author Share Posted December 8, 2006 Well that looks good, but it doesn't work... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 8, 2006 Share Posted December 8, 2006 "It doesn't work" doesn't tell us much.Please tell us how it doesn't work? What does the $_SESSION array contain before this "if" statement?Ken Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 8, 2006 Author Share Posted December 8, 2006 Here is my session array[code] $row = mysql_fetch_array ($result,MYSQL_NUM); mysql_free_result($result); mysql_close(); $_SESSION['user_name'] = $row[1]; $_SESSION['user_id'] = $row[0];[/code]And the if statement doesn't display the admin link at all now Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 8, 2006 Share Posted December 8, 2006 That's how you're putting information into the $_SESSION array.Just before the "if" statement, add this line:[code]<?phpecho '<pre>' . print_r($_SESSION,true) . '</pre>;?>[/code]This will dump the contents of the $_SESSION array.Ken Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 8, 2006 Author Share Posted December 8, 2006 I gotta a parse error when I put that line in.[code]Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /homepages/29/d178597021/htdocs/php/header.php on line 106[/code] Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 8, 2006 Author Share Posted December 8, 2006 nevermind, I just forgot a ' , anyways that totally helped, thanks...much appreciated :D Quote Link to comment 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.