With this snippet of code, I'm attempting to show a clickable link (if "admin" is logged in), which will redirect me to adminarea.php
Right now it just prints out "Admin" in text. Nothing to click on. Just simple text.
Am I missing anything? Surely I got it wrong but I cannot see what's missing.
Here is the code:
<?php if (getUser("user") == "admin") { ?>
<option value="adminarea.php">Admin</option>
<?php } ?>
You're printing an option, which is part of the select form input. You're probably looking for an anchor?
Admin
Possibly a better way to do this would be to declare two options for a variable in your PHP first. Something like:
<?php
if(getUser("user") == "admin") {
$adminlink = 'Admin';
} else {
$adminlink = NULL;
}
?>
And in the html:
<?php echo $adminlink; ?>
This would show the href link if the PHP condition was true, and would display nothing if not. Hope this helps!
Well based on your title am assuming you want a link. By the way you can use PHP friend html syntax instead of making the code look "dirty".
<?php if(getUser("user") == "admin"): ?>
Admin
<?php endif; ?>
Related
Need help with some php to modify a WP plugin which is paid memberships pro. Terrible at php here.
What am trying to do is create one line of code that would say if the membership level equals XXX then print this link. SO the variable I would need are somewhere in this line I imagine:
<li><strong><?php _e('Membership Level', 'paid-memberships-pro' );?>:
</strong> <?php echo $current_user->membership_level->name?></li>
The above is just a snippet of code already found in the page I want to create this if/then link statement.
so something like:
<?php if($Membership Level == $Conflicts of Interest #14124(that's the name
of one level) then print this link.
AM I making sense?
Edit:
Thanks to some help below, this seems to work:
<?php if($membership_level == 'Conflicts of Interest #14124') {
echo "<a href=\"conflicts-of-interest-in-modern-legal-practice-and-internal-
investigations-14124/\">Testing</a>";
}
?>
But the 'Conflicts of Interest #14124' doesn't match even though it is the correct name.
Then general If else statement in the html page
<?php if($membership_level == 'string to be compared') {
echo 'the link that you want to print if it is a string. you can replace this string
with a variable if the value is in variable'
} else {
'any other text if require else you can remove the else block'
}
?>
Hope that helps.
I got a login system, and what I want to do is to hide a div and show another div when the user types the incorrect login details. However it doesn't seem to work.
if(...) { // here I check if the user enters the correct information
... //much code inside
} else { // if incorrect info, do this
echo "<script>$('#jqueryhide2').hide();
$('#jqueryhide').show();</script>";
}
Tried to google a bit but can't find anything that could solve my problem.
put this code and also include your Jquery file -(dont forget)
echo "<script>
$('document').ready(function(){
$('#jqueryhide2').hide();
$('#jqueryhide').show();
});</script>";
I think you should missing the Onclick function like this:
<script>
$('loginId').Onclick(function(){
$('#jqueryhide2').hide();
$('#jqueryhide').show();
});</script>";
You don't need the script tags inside your statement. You can simply do the following. ( Make sure jqueryhide and jqueryhide2 are a part of the DOM. )
if (blah == blah )
{
$('#jqueryhide2').show();
$('#jqueryhide').hide();
}
else
{
$('#jqueryhide2').hide();
$('#jqueryhide').show();
}
Please explain this code. What does "status" and the rest of the code mean?
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks"
<?php // if status=thanks in the query string, display an thank you message instead of the form ?>
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
<p>Thanks for the email! I’ll be in touch shortly!</p>
<?php } else {
Status is an variable from url which is checked for its value is set and value equals to "thanks".
The below code embedded the html and php codes,
The use of below code is you can access both html tags and php values in same file.
<?php
// if status=thanks in the query string, display an thank you message instead of the form
?>
the above code, provide the php comment block, it give suggestion to developer.
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
the above code used to get the value from url (using $_GET variable) (for example www.example.com/index.php?status=thanks)
if the status is set in url and the value is 'thanks' means, html tag will run otherwise run the else part.
<p>Thanks for the email! I’ll be in touch shortly!</p>
else part,
<?php } else {
// do somethink..!!
}
if you r use $_GET method in php first a follow Your URL : https://www.example.in/webhp?status=thanks.check get variable status store value of thanks.After u check in php GET method. like the following code.
<?php
if($_GET['status'] == 'thanks'){?>
<p>Thanks for the email! I’ll be in touch shortly!</p>
<?php }else{?>
<p>Error</p>
<?php }?>
You need konw that:
#See-1 PHP Predefined Variables
#see-2 $_GET is An associative array of variables passed to the current script via the URL parameters.
For example:
you add ?status=thanks
like
http://yourdomain.com/index.php?status=thanks
it will show the <p>Thanks for the email! I’ll be in touch shortly!</p>
if there is no status or the status is not thanks it will not show that comment.
Example:
create file named test.php put it in htdocs localhost
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") : ?>
<p>Thanks for the email! I’ll be in touch shortly!</p>
<?php endif; ?>
try to go to your http://localhost/test.php and http://localhost/test.php?status=thanks and http://localhost/test.php?status=you
check what will be happened?
I want to fetch the landing_page value from this SQL table and add it to header location
: Ive got the following code at the top of the page but this is giving me a blank page:
<?php
foreach($[user_name] as $user) {
$location="Location:http://".$user['landing_page'];
header($location);
}
?>
<!-- if you need user information, just put them into the $_SESSION variable and output them here -->
Order: <?php echo $_SESSION['user_name']; ?>. You are securely logged in.
Where am i going wrong?
The original code is a login script with me trying to make the user to go google.com once logged in
You are not appending the variable properly. Try with,
header('"'.$user['landing_page'].'");
I think you can do this by Simply appending the argument in header
header("Location: " . $user['landing_page']);
try this:
<?php
header("Location: ".$user['landing_page']);
?>
Try this
<?php
foreach($user_name as $user) {
header("Location:http://".$user['landing_page']);
}
?>
or
<?php
foreach($user_name as $user) {
$location="Location:http://".$user['landing_page'];
header($location);
}
?>
I have a navigation bar in which I am trying to show menus/buttons, according to the type of user. I get the type of user via a variable called $isManager.
The good news is that it works on every browser, except firefox.
Code looks like this:
<?php
if ($isManager === '2'){
?>
<li>View</li>
<?php
}
?>
Can you suggest an alternative to this, or is Firefox somehow ignoring or not accepting the true condition here ?
When you use ===, it is for strict checking. So make sure that your$isManager is string type. If it is integer then try
<?php
if ($isManager === 2){
?>
<li>View</li>
<?php
}
?>
You are Using === it means you want to check by its typeof too.
and after that you wrote '2', so it will missmatch the results and not going to the condition, instead try the following.
<?php
if ($isManager === 2){
?>
<li>View</li>
<?php
}
?>