www.webdeveloper.com
Results 1 to 4 of 4

Thread: logged in display form

  1. #1
    Join Date
    Apr 2012
    Posts
    48

    logged in display form

    Hi

    I have made a php script where admin can approve users and once user logged in they are directed to their account page which has a contact form on that they fill out and send to the admin team, what I want though is to only display the form to users and not the admin team as they dont need the form

    I have put the form on the myaccount.php page which both user and admin are directed to after logging in, is there a way to hide the form if admin logs in but display it if user logs in

    Hope that makes sense

    I have added the coding from the myaccount.php page below

    Thank you in advance

    PHP Code:
    <?php 
    include 'dbc.php';
    page_protect();


    ?>

    <?php 
    $title 
    "My Account";

    $pgDesc="";

    $pgKeywords="";

    include ( 
    'includes/header.php' );
    ?>

    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
      <tr> 
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr> 
        <td width="160" valign="top">
    <?php 
    /*********************** MYACCOUNT MENU ****************************
    This code shows my account menu only to logged in users. 
    Copy this code till END and place it in a new html or php where
    you want to show myaccount options. This is only visible to logged in users
    *******************************************************************/
    if (isset($_SESSION['user_id'])) {?>
    <div class="myaccount">
      <p><strong>My Account</strong></p>
      <a href="myaccount.php">My Account</a><br>
      <a href="mysettings.php">Settings</a><br>
        <a href="logout.php">Logout </a>
    </div>
    <?php }
    if (
    checkAdmin()) {
    /*******************************END**************************/
    ?>

          <p> <a href="admin.php">Admin Control Panel </a></p>
          <?php ?>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          <p>&nbsp;</p></td>
        <td width="732" valign="top"><p>&nbsp;</p>
          <h3 class="titlehdr">Welcome <?php echo $_SESSION['user_name'];?></h3>  
          <?php    
          
    if (isset($_GET['msg'])) {
          echo 
    "<div class=\"error\">$_GET[msg]</div>";
          }
                
          
    ?>
          
          <?php
          
          $rs_settings 
    mysql_query("select * from users where id='$_SESSION[user_id]'"); 
          
          
    ?>
          
          <?php while ($row_settings mysql_fetch_array($rs_settings)) {?>
          <form method="post" action="process-form.php" id="contact-form">
            <label for="name">Your Name:</label>
            <input id="name" name="name" type="text" value="<?php echo $_SESSION['user_name'];?>" disabled />
            <div class="clear"></div>
            <label for="email">Your E-mail:</label>
            <input id="email" name="email" type="text" value="<? echo $row_settings['user_email']; ?>" disabled />
            <div class="clear"></div>
            <label for="phone">Your Phone Number:</label>
            <input id="phone" name="phone" type="number" value="<? echo $row_settings['tel']; ?>" disabled />
            <div class="clear"></div>
            <label for="message">Job brief:</label>
            <textarea id="message" name="message" cols="10" rows="9"></textarea>
            
            <label title="No worries, the text entered here is case-insensitive" for="spamtrap">Is Water Wet or Dry
            <span class="required">*</span></label>
            <input name="spamtrap" id="spamtrap" type="text" class="field" value="<?= $_SESSION['spamtrap']; ?>" tabindex="6"/>
            
            <div class="clear"></div>
            
            <input type="reset" class="iePNG" id="clear-button" value=""/>
            <input type="submit" class="iePNG" id="send-button"    value=""/>
            <div class="clear"></div>
          </form>
            <?php ?>
         
          </td>
        <td width="196" valign="top">&nbsp;</td>
      </tr>
      <tr> 
        <td colspan="3">&nbsp;</td>
      </tr>
    </table>

    <?php include( 'includes/footer.php' ); ?>
    Kind regards

    Ian

  2. #2
    Join Date
    Apr 2014
    Posts
    4
    Hi Ian,

    You need to add a method of differentiating between Admin Users and Non Admin Users - this is commonly done using a User Group or some sort of flag.

    User Group

    The more complicated solution - this would involve creating a "User Group" and an "Admin Group" and when people register or are added to the system, you add them to the correct group.

    Then when you display that page, in pseudo code, you would say:

    if the current user belongs to the "User Group"
    show the form
    [the below isn't necessary when writing the code, just to illustrate]
    else if the current user belongs to the "Admin Group"
    don't show the form

    Admin Flag

    This would be the easier way. You simply add an "is_admin" flag to your Users table in your database, then when someone logs in, you would do:

    if current user is_admin flag is set to true
    don't show the form
    else
    show the form

  3. #3
    Join Date
    Apr 2012
    Posts
    48
    Hi Darrentaytay

    Thank you so much for the reply and advice

    I like the thought of the second way, def seems so much easier

    What I have done though as had a thought earlier

    Rather than the admin and user using the same login form page, I copied the login form and the myaccount.php file and other files that the admin side uses and put them into a separate folder called admin and on the myaccount.php page in the admin folder I took the form off and called it admin-account.php and problem is solved

    but thank you so much for replying and advice, really do appreciate it

    Kind regards

    Ian

  4. #4
    Join Date
    Apr 2012
    Posts
    48

    admin form logged in

    Hi Darrentaytay

    Thank you so much for the reply and advice

    I like the thought of the second way, def seems so much easier

    What I have done though as had a thought earlier

    Rather than the admin and user using the same login form page, I copied the login form and the myaccount.php file and other files that the admin side uses and put them into a separate folder called admin and on the myaccount.php page in the admin folder I took the form off and called it admin-account.php and problem is solved

    but thank you so much for replying and advice, really do appreciate it

    Kind regards

    Ian

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles