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.
Related
This question already has answers here:
Add PHP variable inside echo statement as href link address?
(8 answers)
Closed 3 years ago.
I want to make underline at specific part using href in php.
Please help..
Here is my code..
echo "Welcome " . $row1['name'] . "Sir ";
//I want to make underline only this part: $row1['name'];
You can actually put anchor tag directly inside your php echo
echo "Welcome <a href='#yourlink'>" . $row1['name'] . "</a> Sir ";
<?php
echo " Welcome <a href='hyperlink'>" . $row1['name'] . "</a> Sir ";
?>
This will work, without any flow
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 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> ";}
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I have 35.php that includes common menu for my website. 36.php page should display the menu by using include()
Why doesn't this work?
My error:
35.php is shown below;
<?php
echo "Home
PHP
HTML
CSS <br />";
?>
36.php is shown below;
enter code here
<html>
<body>
<?php include("35.php"); ?>
<p>About Menu is imported from 35.php file</p>
</body>
</html>
You missused the ". They include the string but you also used them for the href. But that closes the string
echo "<a href="
This is where the String ends for PHP and it wants either a ; fo finish the statement or a . to connect it to another string.
So this is what you could to to solve it:
echo 'Home
PHP
HTML
CSS <br />';
With switching the "to a ' The string symbol is now the ' and therefor the " can be used int he string normaly.
Otherwise you could also escape the " like this \" inside the string:
echo "Home ...