php if pg true show button on navigation bar - php

I want a button to show on my navigation bar only if the page is = to employees.
I was doing this to accomplish this.
on employees.php
<?php $pg = employees; ?>
on header.php
<?php
if ($pg == $employees)
?>
<?php
<a class="btn btn-info" href="https://www.ebillity.com/Firm4.0/Login.aspx?CorpLogin=1">Time Sheets</a>
?>
Here is the error im getting in the browser
Parse error: syntax error, unexpected '<' in /Applications/XAMPP/xamppfiles/htdocs/lpnew/includes/header.php on line 60

You have done some typing errors, so you have got an error
on employees.php
<?php $pg = $employees; ?>
on header.php
<?php
if($pg == $employees){
?>
<a class="btn btn-info" href="https://www.ebillity.com/Firm4.0/Login.aspx?CorpLogin=1">Time Sheets</a>
<?php } ?>

The error you are getting is because you aren't using echo on your link and you need to swap your double quotes for single quotes.
Try this for your link:
echo "<a class='btn btn-info' href='https://www.ebillity.com/Firm4.0/Login.aspx?CorpLogin=1'>Time Sheets</a>";
It looks like your if statement is not finished either you don't have anything in {}. It also appears you are trying to call the current page? I'm making a few assumptions but try this:
if (basename($_SERVER['PHP_SELF'])== 'employee.php'){
//do something
}
else{
//do something else
}

Related

How to disable and enable anchor tag based on condition using php

How do i disable and enable an anchor tag based on order_status condition? I want to make my receipt button only be able to click when the order_status been updated to ($irow['order_status'] == 5. It would be much appreciated if you all can provide me a code demo to show me how should I implement this using php. Thanks!
I tried the below codes but it wasn't working. It shows the error of Parse error: syntax error, unexpected 'order_id' (T_STRING). I do not know why does this happens. Can you guys give me a help to implement this?
<?php
if($order_status == 5){
print ' <a id="receiptbtn" target="_blank"
href="
receipt.php?order_id=<?php echo $row['order_id']; ?>"
class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>';
}
else{
print 'Receipt';
}
?>
You're already in <?php execution mode, you can't use <?php echo to include a string. <?php is being treated as literal text in the string, and the ' in $row['order_id'] is ending the string that you're printing.
Use the string concatenation operator to combine a variable with the string literal.
To disable a link use href="#". href="" means to reload the page.
<?php
if($irow['order_status'] == 5){
print ' <a id="receiptbtn" target="_blank"
href="receipt.php?order_id=' . $row['order_id'] . '"
class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>';
}
else{
print 'Receipt';
}
?>

Syntax error for variable in the php code

I am make a variable to show the display:none; in the php echo code. But my code function cannot work when I've clicked the Delete button. I think this code is errored to put variable style='.$show_display.', maybe the syntax error. Hope anyone can point out which part I am getting error in the code.
if ($is_delete == "1"){
$show_display = "";
}
if ($is_delete == "0"){
$show_display = "display:none;";
}
echo '<a style='.$show_display.' onclick="delete_folder(\'' . md5($rs_wtp['id'].$md5) . '\',1)" class="btn btn-sm btn-primary" data-color-format="hex">Delete</a>';
I've tried to console the error. The error show me like below the picture:
Issue here is with the missing quotes for style attribute. So the echo statement would look like below:
echo '<a style="'.$show_display.'" onclick="delete_folder(\'' . md5($rs_wtp['id'].$md5) . '\',1)" class="btn btn-sm btn-primary" data-color-format="hex">Delete</a>';

How do i change text inside a button with if-else statement?

Im on a dynamic webpage written in php and would like to have an if else statement that would look inside mysql database table and check if the string "description" is present inside a certain database table column. if the word "description" is present echo "Visit Discounted Venue" text inside the button, else echo "Visit venue website" string inside the button.
I currently have the code below, its in a php file.
<?php if(stripos( $forum_data['venue_url_text'],"discount") == false) ?>
VISIT VENUE WEBSITE
<?php elseif: ?>
VISIT DISCOUNTED VENUE
<?php endif: ?>
<?php
if(stripos( $forum_data['venue_url_text'],"discount") == false)
{
echo '<button class="btn" target="_blank" rel="nofollow"> VISIT VENUE WEBSITE </button>';
}
else {
echo '<button class="btn" target="_blank" rel="nofollow"> VISIT DISCOUNTED VENUE</button>';
}
?>
I don't know if you're using button or input, so replace <button> with <input type="submit" value="VISIT ..." /> if you want input instead of button.
UPDATE: sorry i coded it bad, updated
Try this:
<? if (stripos( $forum_data['venue_url_text'],"discount") !== false): ?>
<a class="btn" target="_blank" rel="nofollow"> VISIT DISCOUNTED VENUE </a>
<? else: ?>
<a class="btn" target="_blank" rel="nofollow"> VISIT VENUE WEBSITE </a>
<? endif; ?>
Hope this helps.
You have to put a colon (:) after if statement declaration, to change elseif condition with else and to put a semicolon (;) instead of colon after endif:
<?php if(stripos( $forum_data['venue_url_text'],"discount") == false): ?>
VISIT VENUE WEBSITE
<?php else: ?>
VISIT DISCOUNTED VENUE
<?php endif; ?>
Heres my solution, using php and regexp:
<?php
$venue_url_button = "Venue Website";
if(preg_match('/discount(.*)/i',$forum_data['venue'['venue_url_text']) ) {
$venue_url_button = "CLICK FOR DISCOUNTED HOTEL ROOMS"; }
else{
$venue_url_button = "CLICK TO VISIT VENUE WEBSITE";
}
?>

echo a session variable in a <a href> over to the next page?

Please can someone help me with this. I have this MySQL query which lists users on my site, and echos a link that can be clicked to take you to the user's profile:
<?php
$online_set = online_channel();
while ($online = mysql_fetch_array($online_set)) {
echo "<div class=\"online_row\"><img width=25px height=25px src=\"data/photos/{$online['user_id']}/_default.jpg\" class=\"online_image\"/><div class=\"online_text\">{$online['display_name']}</div></div>";?>
<? } ?>
The link goes to profile.php and echos the users 'user_id' so it knows which users profile to take you to, and now I am wanting to include a session variable in the link somehow so a message is displayed on that users profile after clicking the link.
I have tried including $_SESSION['chat'] in the link but it doesn't work:
<?php
$online_set = online_channel();
while ($online = mysql_fetch_array($online_set)) {
echo "<div class=\"online_row\"><img width=25px height=25px src=\"data/photos/{$online['user_id']}/_default.jpg\" class=\"online_image\"/><div class=\"online_text\">{$online['display_name']}</div></div>";?>
<? } ?>
I am also trying to execute the session in profile.php by using this:
<?
session_start();
if(isset($_SESSION['chat']))
echo $_SESSION['chat']="<div class=\"infobox-favourites\"><strong>Deleted from Favourites</strong> - This user has successfully been deleted from your favourites.</div><div class=\"infobox-close4\"></div>";
unset($_SESSION['chat']);
?>
What I have tried is not working and i'm not sure i'm doing it right, so I would really appreciate any help with this. Thanks
Try this...for easier debugging the entire code you have
<?php
$online_set = online_channel();
while ($online = mysql_fetch_array($online_set)) {
?>
<div class="online_row">
<a href="profile.php?id=<?php echo $online['user_id'];?>">
<img width=25px height=25px src="data/photos/<?php echo $online['user_id'];?>/_default.jpg/" class="online_image" />
<div class="online_text\">
<?php echo $online['display_name'];?>
</div>
</a>
</div>
<?php
}
?>
Just review the code I posted to learn the better way to echo an entire div

if statement in anchor

I am trying add an if statement to an anchor like so.
<div class="box-button">
<a href="
<?php $header_button = of_get_option('header_text'); ?>
<?php if($header_button){?>
<?php echo of_get_option('header_text'); ?>
<?php } else { ?>
#
<?php } ?>
" class="button">Connect Now</a>
</div>
I can click the button on the homepage and I will get linked to "#" so it is as if wordpress doesn't recognize as a theme option. Is my syntax the problem?
You know you can do the logic outside the html and then insert the result into the href
<?php
$header_button = of_get_option('header_text');
$link = (!empty($header_button)?$header_button:'#');
?>
<div class="box-button">
Connect Now
</div>

Categories