matthew798 Posted September 10, 2008 Share Posted September 10, 2008 <?php session_start(); $username = 'matthew798'; include 'dbconnect.php'; $q = mysql_query("SELECT permission FROM users WHERE username = '$username'") or die(mysql_error()); $permissions = explode(",", $q); print_r($permissions); if ( $permissions['0'] == 0 ){ die('You do not have permission to access this administrative function'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <LINK REL=StyleSheet HREF="stylemain.css" TYPE="text/css" MEDIA=screen /> </head> <body bgcolor="black"> <table border="0"> <tr> <td><form action="newsprocess.php" method="POST"> <span class='headline'>Title</span><br /> <input name="title" type="text" class='textinputhead' /> <br /><br /> <span class='headline'>Body</span><br /> <textarea name="body" type="text" class='textinputbody' /></textarea><br /><br /> <input type="submit" value='Post News' class='textinputsubmit'/> </form></td> </tr> </table> </body> </html> I keep getting this. Array ( [0] => Resource id #4 ) 1: Now a few things i want you to look at, the IF statement. If the value IS NOT 0, then it should just continue with the rest of the page, right? 2: Why isnt it returning all the permission values in the array? (the value in the DB is "1,1,1", i checked) 3: All i have to do is session_start() and it loads all $_SESSION variables i had when they logged in right? I just re-posted this here because the other topic was getting too crowded for my already withered PHP mind... I couldn't find anything anymore. Anyways now it has an appropriate title! Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/ Share on other sites More sharing options...
KevinM1 Posted September 10, 2008 Share Posted September 10, 2008 Try fetching the results: $q = mysql_query("SELECT permission FROM users WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_assoc($q); $permissions = explode(", ", $row[permission]); print_r($permissions); if ( $permissions['0'] == 0 ){ die('You do not have permission to access this administrative function'); } Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/#findComment-638536 Share on other sites More sharing options...
matthew798 Posted September 10, 2008 Author Share Posted September 10, 2008 Thanks!!! IT WORKS!!!! Only thing is: Notice: Use of undefined constant permission - assumed 'permission' in C:\Program Files\EasyPHP 2.0b1\www\admin\adminnews.php on line 10 Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/#findComment-638587 Share on other sites More sharing options...
KevinM1 Posted September 10, 2008 Share Posted September 10, 2008 Thanks!!! IT WORKS!!!! Only thing is: Notice: Use of undefined constant permission - assumed 'permission' in C:\Program Files\EasyPHP 2.0b1\www\admin\adminnews.php on line 10 Comes from a typo I had in the code. Try: $permissions = explode(", ", $row['permission']); Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/#findComment-638598 Share on other sites More sharing options...
matthew798 Posted September 10, 2008 Author Share Posted September 10, 2008 hehe no more warning! But is it normal that Array ( [0] => 1,1,1 ) shouldnt [0] => 1 -- [1] => 1 -- [2] => 1 ? Theres three permissions... Different pages call diferent vars within the string (dunno if my PHP grammar is good there lol) Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/#findComment-638607 Share on other sites More sharing options...
KevinM1 Posted September 10, 2008 Share Posted September 10, 2008 If there's no space between the commas and a permission setting within the 'permission' DB field, then simply rewrite explode as: $permissions = explode(",", $row['permission']); Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/#findComment-638619 Share on other sites More sharing options...
matthew798 Posted September 10, 2008 Author Share Posted September 10, 2008 god i love you <3 Link to comment https://forums.phpfreaks.com/topic/123652-php-explode-string-not-working-properly-cont/#findComment-638622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.