wtfsmd Posted January 7, 2007 Share Posted January 7, 2007 I have set up my MySQL database so when they register it sets up two different tables users:(stores ID, username, password, regdate, e-mail, their website, location, and if they choose to show their e-mail or not) and userranks:(name, rank(registered or admin) the default is registered) and i go in with phpmyadmin and make the admin ranks to who ever i wish.What i need help with is sessions i am guessing here is my code:[code]<?phprequire 'login/db_connect.php';function checkUser($required){if(checkUser(admin)){ echo '<input type="button" name="post_article" method="post" onclick="window.location.href=\..test2.php\">';} if($_SESSION['userranks'] >= $required){ return false; } else{ return true; }}?>[/code]I know i got to be doing something wrong. because when im logged in as admin the button does not appear. I'm just beginning at this stuff and not really sure on what to do, any help would be appreciated thanks. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/ Share on other sites More sharing options...
corbin Posted January 7, 2007 Share Posted January 7, 2007 Ummm you're calling to a function within a function? I think you need to rewrite the function, and also you need session_start() on the page (assuming it's not in db_connect.php) Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154711 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 where are you calling session_start()?Plus what corbin said - your function is recursive and if I'm not mistaken, will cause in infinite loop. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154713 Share on other sites More sharing options...
genericnumber1 Posted January 7, 2007 Share Posted January 7, 2007 There definitely is something wrong... but I cant fix it if I don't understand what you're trying to do.... here's my guess....[code=php:0]function checkUser($required) { if($_SESSION['userranks'] >= $required){ return true; } else { return false; }}if(checkUser(3)){ echo '<input type="button" name="post_article" method="post" onclick="window.location.href=\..test2.php\">';}[/code]this assumes your admin is set up with a number system though. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154715 Share on other sites More sharing options...
corbin Posted January 7, 2007 Share Posted January 7, 2007 Like generic said, that function would rely on numbers (which is a good thing, I think), but the code could easily be tweaked to allow for strings[code=php:0]function checkUser($required) { if($_SESSION['userranks'] == $required){ return false; } else { return true; }}if(checkUser('admin')){ echo '<input type="button" name="post_article" method="post" onclick="window.location.href=\..test2.php\">';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154716 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 im trying to make it so when a admin is logged in they can post articles, and if your not registered, or registered you cannot see the button/box, i think im in a little over my head because as you can tell i didn't come close to doing it right lol. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154717 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 no i do not have it set up as a number system but i can change it so that it is 0 being non registered, 1 being registered, 2 being admin. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154718 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 i used:[code] <?php require 'login/db_connect.php'; session_start() function checkUser($required) { if($_SESSION['userranks'] == $required){ return false; } else { return true; }}if(checkUser('2')){ echo '<input type="button" name="post_article" method="post" onclick="window.location.href=\..test2.php\">';}?> [/code]and i get this error:[code]Parse error: parse error, unexpected T_FUNCTION in /home/content/t/i/m/timeba/html/newsite/test3.php on line 69Which is function checkUser($required) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154721 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Look at the line before that one. You're missing something important.; Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154736 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 lol im retarded Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154737 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Mark it solved ;) Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154763 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 or maybe not it shows up when your not logged in. so that leaves me to believe that it is not working Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154769 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 if($_SESSION['userranks'] == $required){ return false; } else { return true; }False and true are backwards. This says if the user's rank is equal to what you pass, return false. otherwise return true.Switch them. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154770 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 alright that works, looks like i didn't do something right in my database tables because now it wont show up at all, thanks for your help ill mess around w/ it and see if i cant get it working.Thanks for all your help, Cody. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154777 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 print_r($_SESSION) and make sure the values are right. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154780 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 Array ( [username] => Admin [password] => d159167596fd8ac07a8c9cf92150848d )Is what came out Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154788 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 So then...you can deduce....The other variable isn't set. Go from there. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154792 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 Alright so which other variable? i've been looking for about 15 mins, i guess i don't know what im looking for ???.... ill never get this :-\ Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154815 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 [quote]which other variable?[/quote]$_SESSION['userranks'][quote]ill never get this[/quote]Not if you like being spoon fed. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154823 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 [quote author=thorpe link=topic=121330.msg498770#msg498770 date=1168146871]Not if you like being spoon fed.[/quote]heh, i know its horrible i hate asking people to basically do stuff for me, but if i have no idea how to do it or have no clue on what im looking for its gets pretty tough. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154825 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Read the article in my signature. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154827 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 okay how about this, this would help me out alot if someone could please explain to me what these functions do.[code]function checkUser($required) { if($_SESSION['users'] == $required){[/code]1. checkUser is looking for what?2. what is $required doing here?3. Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/content/t/i/m/timeba/html/newsite/index.php:13) in /home/content/t/i/m/timeba/html/newsite/login/check_login.php on line 3could this be causing the problem?4. $_SESSION['user's] - in my database i have this [url=http://overdriveguild.com/uploads/database.JPG]http://overdriveguild.com/uploads/database.JPG[/url] Does this look correct or am i doing this all wrong?5. i apologize for this if this seemed rude in any way, i learn stuff from actually seeing the code, and doing something "advanced" like this is hard for me to ask the correct questions when i'm not exactly sure on what i am looking for.Thanks, for your help i appreciate it allot. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154834 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Isn't checkUser a function you wrote? Why are you asking us what it is looking for...$required is an argument being passed.session_start() has to be called before anything is output to the screen. Move it to the very first line of all your code.When do you get the user info out of the db and into the session? That's when you need to set the session var you are missing. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154835 Share on other sites More sharing options...
wtfsmd Posted January 7, 2007 Author Share Posted January 7, 2007 i have no clue where i got the checkUser someone posted that and i started using it i have no clue what it means lolThanks for all your help ill google myself to death ;) to find the answer that i am seeking, or ill just ask one of my buddies to explain this in detail. Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154839 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 You need to understand the code you use, don't just copy and paste and hope it will work. You have the function, so you should be able to know what it does... Quote Link to comment https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/#findComment-154841 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.