/    Sign up×
Community /Pin to ProfileBookmark

Index page for Admin and Member (User) Help

Hi guys,

I wonder if you could help me out – I have created a index page at below:

What I want to achieve is: an index page for USER and ADMIN. The only different is ADMIN has all the priority of the page.

  • 1.

    For Admin they allow to edit, create user and delete the user and all.

  • 2.

    For User / Member they only allow to view the page and create a new profile of they own.


  • For user they do not need these links:
    Edit Link
    Delete Link

  • The page is almost similar – can anyone help me to make this page reusable for admin_index.php as well as user_index.php – so we only come up with one page instead? Any suggestion would be appreciated.

    Thanks.

    admin.php

    [code=php]
    <?php
    require ‘includes/application_top.php’;

    $data = mysql_query (“SELECT persons.id, persons.name, persons.surname, persons.address, persons.mobile,
    dept.dept_name FROM persons LEFT JOIN dept ON persons.dept_id = dept.id ORDER BY persons.id DESC”) or die (mysql_error());

    ?>

    <!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=iso-8859-1″ />
    <title>Friends Document</title>
    </head>

    <body>
    <h1>Welcome to the admin page</h1>
    <form action=”<?php echo $_SERVER[‘PHP_SELF’];?>” method=”post”>
    <table width=”1000″ height=”60″ border=”0″ cellpadding=”3″>
    <tr>

    <td><a href=”newPerson.php?page=create”>Create User </a></td>
    <td></td>
    <td><a href=”logout.php?page=log_out”>Log Out</a></td>
    </tr>

    <table width=”808″ border=”1″ cellpadding=”3″>

    <tr>
    <th width=”17″>Id</th>
    <th width=”89″>First Name</th>
    <th width=”95″>Surname</th>
    <th width=”160″>Address</th>
    <th width=”84″>Department</th>
    <th width=”105″>Phone</th>
    <th width=”88″>Edit Link</th>
    <th width=”86″>Delete Link</th>
    </tr>
    <?php

    while($row = mysql_fetch_array( $data ))

    {
    ?>
    <tr>
    <td><?php echo $row[‘id’];?></td>

    <td>
    <?php echo $row[‘name’];?>

    <?php
    if(isset($_GET[‘id’]) && (isset($_GET[‘page’]))) {

    if($_GET[‘id’] == $row[‘id’] && $_GET[‘page’] == “create”){
    echo “<div style=color:red;> Created</div>”;
    //echo ‘<div style=”color: red;”> Created</div>’;
    }
    if($_GET[‘id’] == $row[‘id’] && $_GET[‘page’] == “modify”){
    //echo “Modified”;
    echo “<div style=color:red;> Modified</div>”;
    }
    }
    ?>
    </td>
    <!–Printing and pulling all the data–>
    <td><?php echo $row[‘surname’];?></td>
    <td><?php echo $row[‘address’];?></td>
    <td><?php echo $row[‘dept_name’];?></td>
    <td><?php echo $row[‘mobile’];?></td>

    <!–modify.php?= (showing the id)–>
    <!–td><a href = “newForm.php?id=<?php echo $row[‘id’];?>”>Modify User </a></td–>
    <td><a href = “newPerson.php?id=<?php echo $row[‘id’];?>”>Modify User </a></td>

    <td>

    <a href= “deleteConfirm.php?id= <?php echo $row[‘id’];?>”>Delete User</a></td>

    </tr>

    <?php
    }
    ?>
    </table>
    </form>
    </body>
    </html>

    [/code]

    to post a comment
    PHP

    13 Comments(s)

    Copy linkTweet thisAlerts:
    @BelrickFeb 23.2011 — Well

    You know if a person is admin or user. I assume in a session.

    So in that case just use php to make the page as needed

    eg:

    [code=html]
    <!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=iso-8859-1" />
    <title>Friends Document</title>
    </head>
    <body>

    <?php
    switch($_SESSION['user_type']){

    case "admin":
    //create admin page here, either echo or include
    break;
    case "user":
    //create userpage here, either echo or include
    break;
    }

    ?>

    ...

    [/code]
    Copy linkTweet thisAlerts:
    @siabanieauthorFeb 23.2011 — Thanks Belrick,

    So you saying that I shall put it like this:

    [code=php]
    ...
    <?php
    switch($_SESSION['user_type']){

    case "admin":
    //create admin page here, either echo or include
    1. admin.php
    break;
    case "user":
    2. user.php
    //create userpage here, either echo or include
    break;
    }

    ?>
    ...
    ...
    [/code]


    The [user_type] variable here: How would you define it whether the user is admin or user?

    Also, I was thinking to allow the admin do the job e.g. Admin log in then the admin can create / register the new user - once it been register then the user can log in using the username/password that just been created to view their profile.

    Can you tell me how this will works?
    Copy linkTweet thisAlerts:
    @BelrickFeb 23.2011 — Well i dont know your whole code so i assumed you would have a login script that collects the user data from a database. so eg:

    [code=php]

    $qry="SELECT * FROM users WHERE email = '$login' AND password='$password'";
    $result=mysql_query($qry);
    //Check whether the query was successful or not
    if($result) {
    if(mysql_num_rows($result)>0){
    $member=mysql_fetch_assoc($result);
    $_SESSION[user_type] = $member['user_type'];
    ...


    [/code]
    Copy linkTweet thisAlerts:
    @Skylight_LadyFeb 24.2011 — We need more code to help you.

    What Belrick is saying is that if you have not already got a "user_type" or something similar in your database "users" table .... then you should add it and assign the value "admin" for the administrator user and the value "user" for everyone else.
    Copy linkTweet thisAlerts:
    @siabanieauthorFeb 24.2011 — Thanks guys,

    Well here is what I have done with login.php page so far:

    login.php
    [code=php]
    <?php
    session_start();
    $error_msg = "";
    if (isset($_POST['submit'])) {

    $username = (isset($_POST['username'])) ? $_POST['username'] : '';
    $password = (isset($_POST['password'])) ? $_POST['password'] : '';

    if($username && $password) {

    $connect = mysql_connect("localhost", "root", "") or die ("Couldn't connect!");
    mysql_select_db("persons") or die ("Couldn't find the DB");

    $query = mysql_query ("SELECT * FROM users WHERE username = '$username'");

    $numrows = mysql_num_rows($query);
    if ($numrows != 0){

    while ($row = mysql_fetch_array($query))
    {
    $dbusername = $row['username'];
    $dbpassword = $row['password'];
    }

    //Check to see if they are match!
    if ($username == $dbusername && md5($password) == $dbpassword)
    {
    $_SESSION['username'] = $username;
    $_SESSION['is_admin'] = false;

    if ( $username == 'admin' ) {
    $_SESSION['is_admin'] = true;
    }

    header("Location: firstpage.php");
    }
    else
    $error_msg = "Incorrect password!";
    //code of login

    }else
    $error_msg = "That user does not exist!";

    //echo $numrows;
    }
    else
    $error_msg = "Please enter a username and password!";
    }
    ?>

    <html>
    <head><title>Login Page</title>
    </head>

    <body>
    <br />
    <?php
    // require "header.php";
    ?><br />
    <div align="center">
    <table width="200" border="1">

    <?php
    // If $error_msg not equal to emtpy then display error message
    if($error_msg!="") echo "<div id="error_message"style="color:red; ">$error_msg</div><br />";
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <!--form action="login_a.php" method="post"-->
    Username: <input type="text" name="username" /><br /><br />
    Password: <input type="password" name="password" /><br /><br />

    <input type="submit" name = "submit" value="Log in" />
    </form> <p> </p>

    </table>
    </div>
    </body>
    </html>
    [/code]



    What I want to do IF the "admin" log in is: firstpage.php page will display all the content of user information with seach on function in there as well; and there will be a link ie; admin_area.php which this page will have edit, create (create a new user / register), delete links.

    IF it is a user log in then - it firstpage.php will only display all the user information without the link of admin_area.php. On this page also contain a search function.

    Thanks
    Copy linkTweet thisAlerts:
    @Skylight_LadyFeb 24.2011 — Does the login script work at all? Are you being sent to the firstpage.php even tho the page may NOT be built? Any error msg's?
    Copy linkTweet thisAlerts:
    @siabanieauthorFeb 24.2011 — Yes it does, I have created sample DB:

    Table USERS: id, username, password.

    And insert 2 records;

    username | password

    admin |123

    user1 | 456

    When I log in it did go to the firstpage.php - The only thing I'm unsure of is: whether to have a link register on the log in page (in case they are more than one admin)?

    Also, when user admin or user redirect to firstpage I will need to tell which one are them and display a different function of firstpage.
    Copy linkTweet thisAlerts:
    @Skylight_LadyFeb 24.2011 — You can use in the firstpage.php to tell who is who:

    [code=php]echo $username;[/code]

    Also, when you are adding different links for different users to that page and want to use only one page then you should do something like:

    [code=php]if ( $username == 'admin' ) {
    echo "<a href='#'>Admin Link 1</a>";
    } else {
    echo "<a href='#'>User Link 1</a>";
    }[/code]


    If you want to have different links for the different admin's you can add:
    [code=php]else if ( $username == 'admin2' ){
    echo "<a href='#'>Admin Other Link 1</a>";
    }[/code]


    Assuming that the username is different. Or:
    [code=php]
    if ( $username == 'admin' && $id == '1' ) {
    echo "<a href='#'>Admin Link 1</a>";
    } else if ( $username == 'admin' && $id != '1' ){
    echo "<a href='#'>Admin Other Link 1</a>";
    } else {
    echo "<a href='#'>User Link 1</a>";
    }[/code]


    if the username is the same and the user has different id's. e.g super admin has an id of 1 as shown in the above example.
    Copy linkTweet thisAlerts:
    @siabanieauthorFeb 24.2011 — Thanks Skylight_Lady,

    The first suggested does work fine - the only issue I have now is.

    If e.g. admin user log in and admin want to register a new user at the user_mgt page. I want to have a register link there - perhaps the create link can hold all the records for the table PROFILE. Or which one is better? The reason for the register link is, so that user can use the password and username that been registered by the admin to log in and view their profile..

    Any idea?

    At the moment I have these DB table:

    USERS: id, password, username

    PROFILE: id, dept_id, firstname, surname, address, phone, email, dept_name

    DEPT: id, dept_name
    Copy linkTweet thisAlerts:
    @Skylight_LadyFeb 24.2011 — As shown in this code:
    [code=php]if ( $username == 'admin' ) {
    echo "<a href='user_mgt.php'>Register User</a>";
    echo "<a href='#'>Admin Link 1</a>";
    } else {
    echo "<a href='#'>User Link 1</a>";
    }[/code]


    You can add as many echo "<a href='#'>Admin Link 1</a>"; for only the admin to see those pages while the else statement is for links to be shown to everyone else other than the "admin".

    You need to add a new form on the user_mgt page to add all the users details. And ADD it to the database with a query in that page like:
    [code=php]$query = mysql_query ("INSERT INTO users ( username, password ) VALUES ('$username2', '$password')");[/code]
    etc.

    Then with that user added to the database you can display all the users registered in another link with a link on their names or a button beside their name which will bring you to their profile which u can update/add and add the id to the profile table which matches the id in the users table.
    Copy linkTweet thisAlerts:
    @siabanieauthorFeb 24.2011 — Thanks Skylight_Lady,

    Im not 100&#37; get what you trying to explain but will try them.

    BTW, you said I can add as many this
    [code=php]
    "<a href='#'>Admin Link 1</a>";
    [/code]

    as I like..but what is # here? If it's refer to the link that mean I will have a lot of pages? I thought we can just use one page for to show the all user profile?
    Copy linkTweet thisAlerts:
    @Skylight_LadyFeb 24.2011 — 

    # in the link is just used as an example. What # normally does is it refresh's the page. Change # to the page name e.g register.php etc. And "Admin Link 1" to the links title.



    If it's refer to the link that mean I will have a lot of pages?[/QUOTE]
    What do u mean by lots of pages? If you mean that there will be one page each for every user's profile then no. Each users profile should use the same page.

    You have to add links anyway as you can't really keep the user on the same page all the time even tho different data will be displayed. If you are confusing this with CMS's like joomla and wordpress's then they have tons of files but you won't need that amt of files.

    The way i see it is that you can have one page for the users when they login to show their profile but will they stay on your website if there are no other links???

    Also, the admin will need more links to view/edit/delete/search users and their profiles as that is normal.
    Copy linkTweet thisAlerts:
    @siabanieauthorFeb 24.2011 — Hi Skylight_Lady, yes that what I mean and I agree with you. Only one page but it can be used for every user.


    The way i see it is that you can have one page for the users when they login to show their profile but will they stay on your website if there are no other links???
    [/QUOTE]


    Well what I am thinking is they can only view their profile and there is a logout link. I don't know what else I can add at the moment.

    But for the admin I like to add a register link so that admin can register any user and the user can use their password and username to view their profile. I still trying to work this out in admin page. Im still not entire with you about the register thingy.

    Will keep you posted how I getting on. Thanks.
    ×

    Success!

    Help @siabanie spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...