rofl90 Posted March 27, 2008 Share Posted March 27, 2008 Heres my function, it always returns 0... function user_type($page) { $user = $logged_user; $level = mysql_query("SELECT * FROM users WHERE user='$user'"); $level_a = mysql_fetch_array($level); $final_level = $level_a['usergroup']; $check_level = mysql_query("SELECT * FROM userstructure WHERE name='$final_level'"); $check_level_a = mysql_fetch_array($check_level); if ( $check_level_a[''.$page.''] == '1' ) { return "1"; } else { return "0"; } } Heres how I use it in a backend page: ex. testimonials: if(user_type("testimonials") == "0") { header("Location: notallowed.php"); exit(); } Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/ Share on other sites More sharing options...
ohdang888 Posted March 27, 2008 Share Posted March 27, 2008 try putting this: if ( $check_level_a['$page'] == '1' ) { instead of this: if ( $check_level_a['page'] == '1' ) { or is page is a vriable, do this: if ( $check_level_a['{$page}'] == '1' ) { Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501835 Share on other sites More sharing options...
rofl90 Posted March 27, 2008 Author Share Posted March 27, 2008 if ( $check_level_a['{$page}'] == '1' ) { doesn't work, and yes, it's a variable acquired through user_type("myVar") == 0 //etc strange ;S Have I got the wrong syntax? Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501841 Share on other sites More sharing options...
rofl90 Posted March 27, 2008 Author Share Posted March 27, 2008 Btwe I've used ''$var'' and it works.. Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501867 Share on other sites More sharing options...
kenrbnsn Posted March 27, 2008 Share Posted March 27, 2008 The correct syntax for <?php if ( $check_level_a[''.$page.''] == '1' ) { ?> is <?php if ( $check_level_a[$page] == '1' ) { ?> Ken Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501870 Share on other sites More sharing options...
rofl90 Posted March 27, 2008 Author Share Posted March 27, 2008 still doesn't work with that Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501884 Share on other sites More sharing options...
Jeremysr Posted March 27, 2008 Share Posted March 27, 2008 In this line: $user = $logged_user; $logged_user doesn't exist in that scope. If it exists outside the function you should use: global $logged_user; $user = $logged_user; Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501886 Share on other sites More sharing options...
rofl90 Posted March 27, 2008 Author Share Posted March 27, 2008 thanks it worked!!! thanks so much that was hours i took to fix it... and i didn't. thankyou so much! Link to comment https://forums.phpfreaks.com/topic/98085-function-not-evaluating-correctly/#findComment-501914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.