Syntax error for variable in the php code - php

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>';

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';
}
?>

PHP echo anchor link not working

I'm trying to echo a link on a page. It should be a bootstrap button, but it's just coming out as plain text.
This is my code. What am I doing wrong?
echo '<a class="btn btn-info" href='.$url.'>Video Link</a>';
Try this. I have checked it in my localhost and it is working perfectly.
$url = 'https://www.facebook.com/';
echo '<a class="btn btn-info" href='.$url.'>Video Link</a>';
Please let me know if you have any further questions or any problem occurs.
You should wrap the string you are contencating in double quotes, like this
echo '<a class="btn btn-info" href="'.$url.'">Video Link</a>';
href need to be wrapped up with href=""
try -----> href="'.$url.'"
Change this:
echo '<a class="btn btn-info" href='.$url.'>Video Link</a>';
To this:
echo '<a class="btn btn-info" href="'.$url.'">Video Link</a>';
You should not use single quotes inside single quotes so you have to change your code to something like this
echo '<a class="btn btn-info" href="'.$url.'">Video Link</a>';

Parse error:syntax error,unexpected 'echo'(T_ECHO)

I want to create an event calendar but I got this message below after I execute the code below.
Parse error:syntax error,unexpected 'echo'(T_ECHO)
the error is on this line
return '<li id="li-'.$this->currentDate;?> <?php '"class=btn btn-info btn-lg data-toggle="modal" data-target="#myModal""'.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
($cellContent==null?'mask':'').'">'.$cellContent.'</li>'
I'm trying to find the solution, but failed. so, i really hope that someone can help me. thank you...
Try this,
return '<li id="li-'.$this->currentDate;?> <?php echo "class=btn btn-info btn-lg data-toggle='modal' data-target='#myModal'".($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
($cellContent==null?'mask':'').'">'.$cellContent.'</li>'
I think the problem is here,
<?php '"class=btn btn-info btn-lg data-toggle="modal" data-target="#myModal""'.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' '))
HTML part is not getting echoed correctly.

PHP: string data- attribute gets split

So I'm creating buttons from a result set of MySQL query, and binding data- attributes from those results. All fine with numbers and dates, but when the field is a string, the data- attribute created gets split by the whitespaces.
My PHP code:
$options = "";
while($row=mysqli_fetch_array($of)) {
$options .= "<p><a class='btn btn-default btn-open-modal' role='button' data-id=".htmlentities($row["art_id"])." data-name=".htmlentities($row["art_name"]).">See details »</a></p>";
}
When I inspect the button, I get something like data-name="nike" shox="" (if the name in the table is "nike shox"), but data-id="1" is just fine.
How can I get prevent that the data-name gets split?
Change this...
$options .= "<p><a class='btn btn-default btn-open-modal' role='button' data-id=".htmlentities($row["art_id"])." data-name=".htmlentities($row["art_name"]).">See details »</a></p>";
To this...
$options .= '<p><a class="btn btn-default btn-open-modal" role="button" data-id="' . htmlentities($row["art_id"]) . '" data-name="' . htmlentities($row["art_name"]) . '">See details »</a></p>';

php if pg true show button on navigation bar

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
}

Categories