Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to display a "log in" / "log out" link. I want to display the log in link if they are not logged in, etc. I'm having trouble getting this to work. Heres what I've been trying:
<?php if (isset($_SESSION['access_token']))
{ ?> Log out<?php } ?>
<?php
else
{ ?> Log In <?php } ?>
Basically, if the assess_token is set, it will show a link to log out. And if not, a log in link. I keep getting this as an error:
Parse error: syntax error, unexpected T_ELSE
And i've tried this variation:
<?php if (isset($_SESSION['access_token']))
{ echo "Log out" }
else
{ echo "Log In" } ?>
which get me:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
what am i missing here?
You have 2 examples and both have syntax errors:
Parse error: syntax error, unexpected T_ELSE
If you format your code correctly, you found the error:
<?php
if (isset($_SESSION['access_token'])) {
?> Log out<?php
} else {
?> Log In <?php
}
?>
That:
<?php } ?>
<?php
else
{ ?>
is not valid. The PHP intepreter can't handle this! Please use <?php } else { ?>
The second: Use an Syntax-Highlighted editor! You see that the Syntax is not correct.
Escape the " in your code, you forgotten the ; after the echo:
<?php
if(isset($_SESSION['access_token'])) {
echo "Log out";
} else {
echo "Log In";
}
?>
It's normal . look at your echo . There are only double quotes. You have to use (for example) double quotes for echo, and single quotes to delimit logout.php and login.php
echo "<a href='logout.php'>Log out</a>";
Related
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>
I have a very short code snippet but I have been unable to get the result I want. The code is as shown
<?php
$user = true;
if($user==true): ?>
<p>you are already logged in</p>
<?php else: ?>
<p>User value is not set</p>
<?php endif; ?>
on running the code it gives this error:Parse error: syntax error, unexpected 'else' (T_ELSE)
What might be the problem?
It could be a problem with your editor. I had similar problems (more than once) with Atom.
To solve, I just copied the file contents, closed it, reopened, pasted the contents and saved.
The code is fine, as others mentioned in the comments. You should try out this.
#lil your code is looks right only, this is alternate way to get same output if you like you can try this.
<?php
$user = true;
if($user==true)
{
?>
<p>you are already logged in</p>
<?php
}
else
{
?>
<p>User value is not set</p>
<?php
} ?>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have this code:
?php
if ( is_page('1708')) {
<div id="portofoliu"></div>
}
?>
And this my error:
Parse error: syntax error, unexpected '<' in /home/dacproie/public_html/eventos/wp-content/themes/eventos/header.php on line 141
What is wrong in this code?
Can you help me to solve this problem please?
Thanks in advance!
Missing echo:
<?php
if ( is_page('1708')) {
echo '<div id="portofoliu"></div>';
}
?>
You can't mix HTML and PHP this way.
Another option is (for longer HTML code):
<?php
if ( is_page('1708')) {
?>
<div id="portofoliu"></div>
<?php
}
?>
OR
<?php
if ( is_page('1708')) :
?>
<div id="portofoliu"></div>
<?php
endif;
?>
And, of course, PHP begins with <?php but it seems to be just copy&paste error.
Might seem obvious but... You need to escape your html to be a string. Otherwise PHP trys to execute it.
<?php
if ( is_page('1708')) {
echo '<div id="portofoliu"></div>';
}
?>
You forgot to close and open PHP tags:
<?php
if ( is_page('1708')) {
?>
<div id="portofoliu"></div>
<?php
}
?>
try
<?php
if ( is_page('1708')) {
echo '<div id="portofoliu"></div>';
}
?>
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
I am trying to display the logout button only if any user is logged in.
following is the code:
<?php
if(isset($_SESSION['user']))
{ echo '<li><a href='logout.php'>Logout</li>'; }
?>
But it is giving error.
Error:Parse error: syntax error, unexpected 'logout' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\index.php on line 42
Help me to display this link.
You can't use unescaped ' characters in string literals delimited by ' characters. Either:
Use " instead
Escape the '
Drop out of PHP mode and just write the HTML as normal template code
Such:
<?php
if(isset($_SESSION['user'])) {
?>
<li><a href='logout.php'>Logout</li>
<?php
}
?>
You are closing your quotes and opening them again. Try this:
<?php
if(isset($_SESSION['user'])) {
echo '<li><a href="logout.php">Logout</li>';
}
?>
Note the double quotes.
Alternatively, escape the quotes like this:
<?php
if(isset($_SESSION['user'])) {
echo '<li><a href=\'logout.php\'>Logout</li>';
}
?>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The simplest question but I can't get it working... What's wrong with the way I'm trying to add an image to this php file?
<?php header("HTTP/1.0 404 Not Found"); ?>
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<h1 class="error"><?php echo t('Page Not Found')?></h1>
<?php echo t('We could not find a page at this address.')?>
<?php if (is_object($c)) { ?>
<br/><br/>
<?php $a = new Area("Main"); $a->display($c); ?>
<?php } ?>
<?php
echo "<img src="img.jpg">"
?>
<?php echo t('Back to Home')?>.
The file named img.jpg sits in the same directory as this .php file. When it runs, I see this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in line 21 where line 21 is echo "<img src="img.jpg">".
instead of :
echo "<img src="img.jpg">";
you can do:
echo "<img src='img.jpg'>";
or
echo '<img src="img.jpg">';
or even escape the quote:
echo "<img src=\"img.jpg\">";
Two, or possibly three, things are wrong with the way you're adding an image.
You need to use different kinds of quotation marks (" vs '), otherwise they cancel each other out.
You need a ; to end the line in PHP
Your image path may be broken. If img.jpg is not in the same directory as the PHP script, it won't work.
Replace:
"<img src="img.jpg"/>"
with
"<img src='img.jpg'/>";
If the problem is with your image path, try using an absolute path (src="http://example.com/your/path/img.jpg") instead of the relative path (src="img.jpg"). If that works, then it means that the relative path was wrong.
You have a wrong quotation on the img line and then I suggest keeping it all in PHP. You can replace your code with this code which is more easy to read and maintain:
header("HTTP/1.0 404 Not Found");
defined('C5_EXECUTE') or die("Access Denied.");
echo '<h1 class="error">'. t('Page Not Found') .'</h1>';
echo t('We could not find a page at this address.');
if (is_object($c)) {
echo '<br /><br />';
$a = new Area("Main");
$a->display($c);
}
echo "<img src='img.jpg'>";
echo ''. t('Back to Home') .'.';