Jump to content

Recommended Posts

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]<?php
require '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.
Link to comment
https://forums.phpfreaks.com/topic/33171-help-with-some-php-mysql/
Share on other sites

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.
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]
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.
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 69

Which is  function checkUser($required) {[/code]
[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.
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 3
could 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.
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.
i have no clue where i got the checkUser someone posted that and i started using it i have no clue what it means lol

Thanks 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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.