I am not able to find the error why my title is not displaying. This is my code:
echo '<br /><b style="display:block";>'.$name .'</b>';
echo '<i style="color:red";>'.$class.'';
Can you please help me?
Remove the unnecessary last single quotes '', Also put your semicolon ; inside the double quotes "
<?php
$title = 'this is title value'; //example title
$des = 'this is description'; // example description
echo '<br /><b style="font-size:1.5em;">'.$title.'</b>';
echo '<i style="font-size:18px;">'.$des;
?>
DEMO: https://eval.in/1044486
It is not recommended to echo HTML tags inside PHP script. Your code should have been written as follows. I see that closing tag </i> is missing as well. I hope this might solve your problem.
<br />
<b style="display:block;">
<?php echo $name;?>
</b>
<i style="color:red;">
<?php echo $class;?>
</i>
Related
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';
}
?>
echo '<li><span class="glyphicon glyphicon-user"></span>Welcome echo $_SESSION["username"];</li>';
In the above code it is not displaying username variable.. instead it is simply echoing Welcome $_SESSION["username"];
FYI.. I have used session.start() in both the files
But how to display Welcome 'username'
You have an error. you should close quotes.
echo '<li><span class="glyphicon glyphicon-user"></span>Welcome' .$_SESSION["username"].'</li>';
If still doesn't show the username:
Turn on error_reporting or use var_dump to cehck if variable is set
<?php
error_reporting(-1);
<?php
var_dump($_SESSION);
and just note about templating. If you use this in a view (most of code is html) then try to use php temlating
<li>
<a href="signup.html">
<span class="glyphicon glyphicon-user"></span>Welcome <?= $_SESSION["username"] ?>
</a>
</li>
The part Welcome echo $_SESSION["username"]; is simply a STRING and would be echoed verbatim without any Evaluation, Processing or Parsing. And, by the way: You don't use an echo Statement within an echo statement. That should be like SAYING GOOD MORNING IN ENGLISH & GERMAN AT THE SAME TIME THROUGH THE SAME ONE SINGLE MOUTH: LOL :-)
You should have used Double Quotes to surround the String you wished to echo out and then use single quotes for the HTML DOM Element Attributes like "class" or "HREF". That way you, you could very easily echo your String without much fuss. Here's how:
<?php
echo "<li>
<a href='signup.html'>
<span class='glyphicon glyphicon-user'></span>Welcome {$_SESSION['username']}
</a>
</li>";
Try this
echo '<li><span class="glyphicon glyphicon-user"></span>Welcome '. $_SESSION["username"] .'</li>';
Is it possible to put quotes inside quotes?
If so how?
Here is my code:
<?php
echo '<span onclick="$(this).addClass('selected');"> </span>';
?>
According to php.net
To specify a literal single quote, escape it with a backslash (\).
It means you could have:
<?php
echo '<span onclick="$(this).addClass(\'selected\');"> </span>';
?>
Heredoc is the perfect solution for this:
<?php
echo <<< HereDocString
<span onclick="$(this).addClass('selected');"> </span>
HereDocString;
?>
You could do this:
<?php
// some code
?>
<span onclick="$(this).addClass('selected');"> </span>
<?php
// some more code.
?>
I am having a problem with this code
<?php
echo '<div class="post_note2">
<b>'.$lang['RENEW_SUCCESS'].'</b></div><br /><span class="orange"><b>HOME|VIEW AD</b></span>';
}
}?>
for some reason when the VIEW AD link is clicked it doesn't build it properly and still contains the php code in the link rather than the link to the actual ad page. is it an issue with an echo in an echo ?
I'm sure this isn't quite difficult to solve but I have been trying for far to long on my own and cant get it.
Thanks, any help would be great.
You actually had it right in the first part of your string. You can't have and echo statement inside of another echo statement. Use concatenation throughout your string:
<a href="' . $adurl . '"
You have two extra brackets at the end and php text inside your echo.
<?php
echo '
<div class="post_note2">
<b>'.$lang['RENEW_SUCCESS'].'</b>
</div>
<br />
<span class="orange">
<b>
HOME | VIEW AD
</b>
</span>';
?>
All fixed given that $adurl is defined.
This
<?php echo $adurl; ?>
Should be
' . $adurl . '
i.e.
echo '<div class="post_note2"><b>'.$lang['RENEW_SUCCESS'].'</b></div><br /><span class="orange"><b>HOME|<a href="'.$adurl.'>VIEW AD</a></b></span>';
I'm trying to call an HTML/PHP content that it's inside my database using:
<?php echo $row_content['conteudo']; ?>
When the row is called the HTML appears correctly but the PHP doesn't.
I belieave it's cause of the echo inside the main echo.
<?php echo "
<h3>Hello</h3>
<?php do { ?>
<div class=\"indios\">
<a href=\"indio.php?id=<?php echo $row_indiosct['id']; ?>\">
<img src=\"galeria/indios/<?php echo $row_indiosct['foto']; ?>\" alt=\"<?php echo $row_indiosct['nome']; ?>\" />
<br /><?php echo $row_indiosct['nome']; ?></a></div>
<?php } while ($row_indiosct = mysql_fetch_assoc($indiosct)); ?> "
?>
The line one of this code is the same echo as the first code field, it's not repeating, it's there just for help and to understand where is the problem.
I already fixed some quotation marks but it gives an error in the line of the 1st echo.
That is some of the ugliest code I have ever seen...
<?php
echo '
<h3>Hello</h3>';
while ($row_indiosct = mysql_fetch_assoc($indiosct))
{
echo '
<div class="indios">
<a href="indio.php?id='.$row_indiosct['id'].'">
<img src="galeria/indios/'. $row_indiosct['foto'].'" alt="'.$row_indiosct['nome'].'" />
<br />'.$row_indiosct['nome'].'</a>
</div>';
}
?>
You could also use the HEREDOC syntax.
Don't do this. Multi-line echoes, especially when you've got embedded quotes, quickly become a pain. Use a HEREDOC instead.
<?php
echo <<<EOL
<h3>Hello</h3>
...
<div class"indios">
...
EOL;
and yes, the PHP inside your echo will NOT execute. PHP is not a "recursively executable" language. If you're outputting a string, any php code embedded in that string is not executed - it'll be treated as part of the output, e.g.
echo "<?php echo 'foo' ?>"
is NOT going to output just foo. You'll actually get as output
<?php echo 'foo' ?>
You have misunderstood how PHP works. PHP is processed by the server. When it encounters your script, it sees the following:
<?php echo "some long piece of text that you have told PHP not to look at" ?>
What is the reasoning behind trying to nest PHP calls inside strings?
evaluate code php in string using the function eval(): this post Execute PHP code in a string
<?php
$motto = 'Hello';
$str = '<h1>Welcome</h1><?php echo $motto?><br/>';
eval("?> $str <?php ");
http://codepad.org/ao2PPHN7
also if your need the code buffer output in a string also you can using the ob_start() method:
<?php ob_start(); ?>
<h3>Hello</h3>;
<?php
while ($row_indiosct = mysql_fetch_assoc($indiosct)){ ?>
<div class="indios">
<a href="indio.php?id='<?php echo $row_indiosct['id']'">
<img src="galeria/indios/'<?php echo $row_indiosct['foto'].'" alt="'.$row_indiosct['nome'].'" />
<br />'.$row_indiosct['nome'].'</a>
</div>';
<?php } ?>