/    Sign up×
Community /Pin to ProfileBookmark

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

[code=php]
<?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’ ); ?>

[/code]

Kind regards

Ian

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@darrentaytayJul 26.2014 — 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.

[B]User Group[/B]

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

[I][the below isn't necessary when writing the code, just to illustrate][/I]

else if the current user belongs to the "Admin Group"

don't show the form

[b]Admin Flag[/b]

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
Copy linkTweet thisAlerts:
@ianhaneyauthorJul 26.2014 — 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
Copy linkTweet thisAlerts:
@ianhaneyauthorJul 26.2014 — 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
×

Success!

Help @ianhaney 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.18,
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,
)...