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> ";}
Related
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.
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 "";
}
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>
Take a look at that. You can't use echo command inside of an echo " " line. Try using ' inside and not \ may help you too from confusion.
<?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>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Hi I'm kind of new to the site and to php. I am trying to make a code which tells hello to a user if logged in or displays the Register/Login form if the user is logged out. Following is the code for it :
<?php if(empty($_SESSION['user']))
{echo " <a href=register.php >Register </a> Or <a href=login.php>Login</a>" ;
}
else{
Hello htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); you currently have $_SESSION['user']['point']; points !
}. ?>
But it gives me an error :
PHP Error Message
Parse error: syntax error, unexpected T_STRING in /home/a3897717/public_html/index1.php on line 63
And the 63rd line is this one :
Hello htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); you currently have $_SESSION['user']['point']; points !
Please if anyone can help me, Please help !
Thanks in advance ! This not the duplicate i just want someone to tell me where i am wrong and correct that mistake .
You missed a echo before your output string:
echo "Hello " . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
echo "you currently have " . $_SESSION['user']['point'];
echo "points !";
You're messing up with the concatenation.
Change this:
echo "<a href=register.php >Register </a> Or <a href=login.php>Login</a>";
to this:
echo "<a href='register.php'>Register </a> Or <a href='login.php'>Login</a>";
and this:
Hello htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); you currently have $_SESSION['user']['point']; points !
to this:
echo "Hello " . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8') . "you currently have " . $_SESSION['user']['point'] . "points!";
EDIT:
Since I could not find a online PHP/HTML compiler, to show that the above code works I have attached a picture:
Note: It is obvious that the error is shown as the sessions are not
defined and neither was the core problem of this question.
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?).