Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP: Looking to check 'adminlevel' from database

Options
  • 30-11-2015 6:30pm
    #1
    Registered Users Posts: 1,374 ✭✭✭


    Hey guys. I've been doing this project for college and I'm just a bit stuck. It's a proper n00b question so please bear with me and my knowledge of html/php.

    I just want to know how to get a value from a database under the column 'adminlevel' for the current session's username to check if it is an admin or not and redirect accordingly. The redirect, I'm pretty sure I can handle. But I've been trying different solutions in the past 4 hours for the database check and I just couldn't make it work.

    Any help would be appreciated :D Thank you.


Comments

  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Are you going to share what you've tried so far?


  • Registered Users Posts: 1,374 ✭✭✭LeakingLava


    Graham wrote: »
    Are you going to share what you've tried so far?

    Oh. Well I've deleted the pieces of code that I added as I went along and didn't really keep track.

    Here's one of the links where I took bits and pieces from:

    http://stackoverflow.com/questions/19309221/login-as-admin-and-normal-user

    I tried to do this but I keep getting undefined variable 'adminlevel' as an error.

    To be honest with you, I really have no idea what I've done or not done anymore as I did quite a lot of changes on the code.

    The other problem is that most of the main php code that I have here are given to me by my lecturer. The only thing I was thinking of getting from here when I posted was the very basic idea of how to do such a thing so I could maybe actually understand what the code in front of me means. I'm even getting confused regarding the basic principle of variables as the wamp thing keeps telling me I have 'adminlevel' undeclared when I just inserted the exact same lines for 'adminlevel' where the other variables like username and password exists.


  • Registered Users Posts: 1,374 ✭✭✭LeakingLava


    Here are some screenshots of the main pages I'm working on. The admin page is where I'm trying to do the 'check' for admin level. I know that code that I have there is most likely all wrong. Too confused already. Some of the codes that are there might not even belong to the exact solution that it was meant to be with. Might have mixed up 5 or 6 different solutions :o


  • Registered Users Posts: 6,150 ✭✭✭Talisman


    This takes the help me do my homework threads to a whole new level. Style points for adding images of the code, I haven't seen that before.

    It's terrible code to copy, the comments on the Stack Overflow thread explain some of the reasons why. Read: PHP Security Cheat Sheet

    A simple Google search for "PHP login system" would have given you better scripts to knock off for your project.

    e.g. How to Create a Secure Login Script in PHP and MySQL


  • Registered Users Posts: 1,374 ✭✭✭LeakingLava


    Talisman wrote: »
    This takes the help me do my homework threads to a whole new level. Style points for adding images of the code, I haven't seen that before.

    It's terrible code to copy, the comments on the Stack Overflow thread explain some of the reasons why. Read: PHP Security Cheat Sheet

    A simple Google search for "PHP login system" would have given you better scripts to knock off for your project.

    e.g. How to Create a Secure Login Script in PHP and MySQL

    Well, to be quite honest with you, even our lecturer have said that for this project, we don't even need to worry about the security bit. And I was just using his format as well. But I will look into those sites.

    Sorry for being a total noob. No idea that there was a general format. I actually don't know why I posted a pic instead of the code. :o


  • Advertisement
  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Nobody minds Noobs, what most people like to see is that you've at least attempted it yourself.

    We're a cynical bunch (I am anyhoo) so if you don't show your previous efforts it's assumed this is a 'please do my homework' thread.


  • Registered Users Posts: 6,252 ✭✭✭Buford T Justice


    Can you tell us what you've actually tried first?


  • Registered Users Posts: 6,150 ✭✭✭Talisman


    Well, to be quite honest with you, even our lecturer have said that for this project, we don't even need to worry about the security bit. And I was just using his format as well. But I will look into those sites.
    That's all well and good but sooner or later you will realise that you need to stand out from the flock that is your fellow class mates. Don't let being a noob stop you.

    It's very easy to pick up bad habits particularly with PHP because resources are so common on the web. Bad habits die hard so the best advice I can give you is to take the time to learn to use best practices from the start.

    A potential benefit of learning and using best practices now is that they will become second nature, it will also be noticed by potential employers if they review code from your course work.


  • Registered Users Posts: 1,374 ✭✭✭LeakingLava


    Talisman wrote: »
    That's all well and good but sooner or later you will realise that you need to stand out from the flock that is your fellow class mates. Don't let being a noob stop you.

    It's very easy to pick up bad habits particularly with PHP because resources are so common on the web. Bad habits die hard so the best advice I can give you is to take the time to learn to use best practices from the start.

    A potential benefit of learning and using best practices now is that they will become second nature, it will also be noticed by potential employers if they review code from your course work.

    Thank you. I am off college tomorrow so I will look into all of this further tomorrow.


    Thanks a lot everyone.


Advertisement