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 Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/ 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 Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137720 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... Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137726 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 Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137730 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 Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137731 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 Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137736 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] Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137782 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 Link to comment https://forums.phpfreaks.com/topic/29979-resolved-having-a-problem-with-an-if-statementagain/#findComment-137791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.