NuMan Posted December 30, 2008 Share Posted December 30, 2008 So i have a query which is fully working but my session won't work. i am currently using this: $_SESSION['admin'] = $user_data['admin'] == 1; user_data is the name of my working query. this won't work though it won't set the session admin. Any help? Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/ Share on other sites More sharing options...
revraz Posted December 30, 2008 Share Posted December 30, 2008 That makes no sense. What exactly are you trying to do? Do you want $_SESSION['admin'] = $user_data['admin']? Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/#findComment-725930 Share on other sites More sharing options...
xtopolis Posted December 30, 2008 Share Posted December 30, 2008 Are you trying to use the ternary operator? $value = (condition) ? value if true : value if false; $_SESSION['admin'] = ($user_data['admin'] == 1) ? true : false; //$_SESSION['admin'] will be TRUE if $user_data['admin'] == 1, false otherwise Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/#findComment-725932 Share on other sites More sharing options...
NuMan Posted December 30, 2008 Author Share Posted December 30, 2008 Are you trying to use the ternary operator? $value = (condition) ? value if true : value if false; $_SESSION['admin'] = ($user_data['admin'] == 1) ? true : false; //$_SESSION['admin'] will be TRUE if $user_data['admin'] == 1, false otherwise im just trying to create the session admin if $user_data['admin'] = 1. I will try what you posted and edit this post with the result. Thanks in advanced! EDIT: I did this: <?php if(isset($_SESSION['admin'])){ echo "hey"; }else{ echo "";} ?> And it just says hey to everyone even if their admin is set to 0. Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/#findComment-725940 Share on other sites More sharing options...
peranha Posted December 30, 2008 Share Posted December 30, 2008 <?php if ($user_data['admin'] == 1) { $_SESSION['admin'] = ''; //Place something between the 2 ' } ?> Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/#findComment-725942 Share on other sites More sharing options...
xtopolis Posted December 30, 2008 Share Posted December 30, 2008 $_SESSION['admin'] = ($user_data['admin'] == 1) ? TRUE : FALSE; if($_SESSION['admin'] === TRUE){ echo 'Hey'; }else{ echo 'Nay'; } Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/#findComment-725944 Share on other sites More sharing options...
NuMan Posted December 30, 2008 Author Share Posted December 30, 2008 Are you trying to use the ternary operator? $value = (condition) ? value if true : value if false; $_SESSION['admin'] = ($user_data['admin'] == 1) ? true : false; //$_SESSION['admin'] will be TRUE if $user_data['admin'] == 1, false otherwise im just trying to create the session admin if $user_data['admin'] = 1. I will try what you posted and edit this post with the result. Thanks in advanced! $_SESSION['admin'] = ($user_data['admin'] == 1) ? TRUE : FALSE; if($_SESSION['admin'] === TRUE){ echo 'Hey'; }else{ echo 'Nay'; } Thank you very much! that solved my problem. Link to comment https://forums.phpfreaks.com/topic/138831-right-way-of-checking-if-query-1/#findComment-725946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.