How to display quote marks within an If statement [duplicate] - php

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I have the below code with a shortcode for a contact form within an if statement, but the contact form doesn't show. I think its because I have displayed quote marks in the wrong place, but i'm a bit confused as to where they should go
My code is:
<?php
if ($postid == "page-international.php" or $postid == "page-international-training.php" or $postid == "page-international-courses.php" or $postid == "page-international-training-course-detail.php") {
echo "<div class='get-ebook'><img class='close-ebook' src='https://www.pescado.co.uk/wp-content/themes/entyce/images/close-button-get.png' /><p class='title'><strong>Is your <br>scaffolding safe?</strong></p><span class='img'><img src='http://dev14.entycestudio.co.uk/wp-content/themes/custom/images/get-ebook.png' />
</span><?php echo do_shortcode('[contact-form-7 id='6664' title='ebook']' ); ?>
</div>";
} else {
echo "";
}
?>
If anyone could help, or point me in the right direction, it would be greatly appreciated :-)
Thanks

your problem might be the fact you have do_shortcode in a echo ""; try removing it from there. like so
echo "<div class='get-ebook'><img class='close-ebook'
src='https://www.pescado.co.uk/wp-content/themes/entyce/images/close-
button-get.png' /><p class='title'><strong>Is your <br>scaffolding
safe?</strong></p><span class='img'><img
src='http://dev14.entycestudio.co.uk/wp-content/themes/custom
/images/get-ebook.png' />
</span>";echo do_shortcode('[contact-form-7 id="6664" title="ebook"]' );
echo "</div>";
} else {
echo "";
}

Related

display an img src inside html then php [duplicate]

This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 5 months ago.
I would like to ask how to display an img src like this:
<html>
<?php
$extradata = (Data for this come from database that I decode)
$profilepicturefinalpath = "/folder/folder/".$extradata;
echo '<img src="<?php echo $profilepicturefinalpath ?>"/>';
?>
</html>
What should I do, Is this possible?
Please help, I am just a newbie
Please try below code. Normal echo with double quotes or heredoc
<html>
<body>
<?php
$extradata = (Data for this come from database that I decode)
$profilepicturefinalpath = "/folder/folder/".$extradata;
echo <<<EOQ
<img src="{$profilepicturefinalpath}" />
EOQ;
echo '<BR>';
echo "<img src='{$profilepicturefinalpath}' />"
echo '<BR>';
?>
</body>
</html>

Why does <?= work only sometimes where <?php works? [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 2 years ago.
Inside the body of an html document I have something like this:
<?=str_replace(' ', '_', $result[0]['something'])?>
This works perfectly fine. In the same document I have this:
<?php if(!empty($result[0]['something'])) { echo "Hello"; } else { echo " "; }?>
Which also works fine, but it slightly bothers me that I am using <?= in one place and <?php in another. When I try to change the if code to become:
<?=if(!empty($result[0]['something'])) { echo "Hello"; } else { echo " "; }?>
or
<?= if(!empty($result[0]['something'])) { echo "Hello"; } else { echo " "; }?>
Both result in a Parse error: syntax error, unexpected 'if' (T_IF) in....
I've attempted to find some documentation on the respective differences between <?php and <?= as a php opening tag but all I get is data on short tags - which this is not. Can someone explain this behavior for me?
<?= is like <?php echo. You can't echo an if statement.

php if then else statement syntax error somewhere [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
So I am getting the following parse error when this file loads:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING)
I have tried everything to work out why and I narrowed it down to the
href=\"start.php?id=<?php echo $res['id'] ?>\"
section of the code. I am sure I left out a ' or " but unsure where as it all makes sense to me. Can anyone with a keener eye see where I am going wrong? Thank you.
My code:
<td>
<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";}
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id'] ?>\">Start Test</a> ";}
?>
</td>
echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id'] ?>\">Start Test</a> ";
}
Is incorrect, you are closing the PHP code before you are done with the PHP code. And $res['id'] cannot be in your echo like that, you should interpolate the variable correctly in the string. Remove the starting and closing tag inside the echo like this:
echo "<a class=\"buttonTest\" href=\"start.php?id={$res['id']}\">Start Test</a> ";
Please check this awesome guide on how to fix these kind of syntax errors.
You cant had snippet in echo use simple string concatenation
<td>
<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";}
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=".$res['id']."\">Start Test</a> ";}
?>
</td>
Try this
echo "<a class=\"buttonTest\" href=\"start.php?id=" . $res['id'] . " \">Start Test</a> ";}

Concatenating HTML and PHP [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Im trying to echo the content of the foreach loop inside div tag but I get an error message. I know my making a mistake in concatenating html and php but Im not sure where I'm making the mistake. Can some one point me in the right direction?
<php
for($i=0; $i<$daysInTheMonth; $i++){
if($i==$firstDayOfMonth)
$BeginMonth= true;
if($BeginMonth){
$CounterForDays++;
echo "<div class=dateContainner> ".$CounterForDays <br/> ;
foreach ($_POST['mondayTime'] as $Times ){
echo "$Times <br>" ;
}
."</div>";
}
else
echo "<div class=dateContainner> </div>";
}
?>
Use this code
if($BeginMonth){
$CounterForDays++;
echo "<div class=dateContainner> ".$CounterForDays." <br/>" ;
foreach ($_POST['mondayTime'] as $Times ){
echo $Times."<br>" ;
}
echo "</div>";
}

Echo arrays with regular text [duplicate]

This question already has answers here:
Print string with a php variable in it
(4 answers)
Closed 11 months ago.
How would I write this so I'm only using one echo?
echo "<div class='post'>";
echo $row['title'];
echo "</div>";
I'm using an array to echo out a table's values but it would be a lot easier on the eyes if I could combine these into one echo statement. However, when I try to the page goes blank.
echo "<div class=\"post\">{$row['title']}</div>";
Other ways of doing the same thing:
echo '<div class="post">'.$row['title'].'</div>';
echo sprintf('<div class="post">%s</div>', $row['title']);
<div class="post"><?php echo $row['title'] ?></div>
you forgot to close the div
> echo "<div class='post'"; should be
> echo "<div class='post'>";
Enclose the array reference in brackets:
echo "<div class='post'{$row['title']}</div>";
<?php
echo "<div class='post'".$row['title']."</div>";
?>
echo '<div class="post">' . $row['title'] . '</div>';
The . operator concatenates strings. Also, I believe HTML wants you to use double quotes for class="post" (although perhaps it doesn't care?).

Categories