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
So on my website im making it where if a member is not sign in they can't see username My account or settings link
this is what i have so far
<?php
if(empty($_SESSION['user'])){
echo "<li>
Register Account
</li>
<li>
Login Account
</li>";
} else {
echo "<li class='dropdown'>";
echo "<a class='dropdown-toggle' data-toggle='dropdown'>
<span class='username'><?php echo $_SESSION['user']['username'];?></span>
<b class='caret'></b>
</a>";
echo "<ul class='dropdown-menu'>
<li><i class='icon-user'></i> My Profile</li>
<li><i class='icon-tasks'></i> My Tasks</li>
<li><i class='icon-calendar'></i> Calendar</li>
<li class='divider'></li>
<li><i class='icon-key'></i> Log Out</li>
</ul>
</li>";
}
?>
This is the error code i receive
Error i get is Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/html/index.php on line 92
You have a echo statement in another echo statement!
So change this:
echo "<a class='dropdown-toggle' data-toggle='dropdown'>
<span class='username'><?php echo $_SESSION['user']['username'];?></span>
<b class='caret'></b>
</a>";
To this:
echo "<a class='dropdown-toggle' data-toggle='dropdown'>
<span class='username'>" . $_SESSION['user']['username'] . "</span>
<b class='caret'></b>
</a>";
Related
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 4 years ago.
Improve this question
Im new to php and i am trying study how to design web page, the code is not mine. My problem is , i have some clickable done using a table for that i have an array
$buttons=array('Home'=>'home.php',
'Contact'=>'contact.php',
'Services'=>'service.php',
'Site map'=> 'map.php');
and there is a function
function DisplayMenu($buttons)
{
echo "<table width='100%' bgcolor
='white' cellpadding='4'
cellspacing='4'\n";
echo "<tr>\n";
$width =100/count($buttons);
while (list($name, $url)=each ($buttons))
{
$this-> DisplayButton($width, $name,
$url);
}
echo "</tr>\n";
echo "</table>\n";
}
and for displaying the button there is also a function
function DisplayButton($width, $name, $url)
{
echo " <td width='$width%'>
<a herf ='".$url."'>
<img src= 'ab.jpg' alt='$name'
border='0'>
</a> <a herf='".$url."'><span
class ='menu'>
".$name."</span></a></td>";
}
My problem is when i click for example the home button its not taking me to the home.php page , can someone help me ?
Just a typo (herf to href)
function DisplayButton($width, $name, $url)
{
echo "
<td width='{$width}%'>
<a href='{$url}'>
<img src='ab.jpg' alt='{$name}' border='0'>
</a>
<a href='{$url}'>
<span class='menu'>{$name}</span>
</a>
</td>
";
}
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 6 years ago.
Improve this question
I am trying to create an if else statement where if the "if" part is true, a menu icon is displayed that says "Registration" and takes the user to a registration page. If the "else" part is true, the menu will display the user's name that is registered. I have attached basically how I would like it to look, I just do not know how to incorporate my div into a PHP if else statement.
<?PHP
session_start();
if ($_SESSION['email'] == '')
{
"<div id='cssmenu'>
<ul>
<li>
Registration
</li>
</ul>
</div>"
}
else
{
"<div id='cssmenu'>
<ul>
<li>
<a> "Greetings " . $_SESSION['fname'] </a>
</li>
</ul>
</div>"
}
?>
The following should do the trick. As mentioned by #Ghost, you need echo and you needed to change a few quotes to single quotes.
<?PHP
session_start();
if ($_SESSION['email'] == '')
{
echo "<div id='cssmenu'>
<ul>
<li>
<a href='registration.php'> Registration</a>
</li>
</ul>
</div>";
}
else
{
echo "<div id='cssmenu'>
<ul>
<li>
Greetings " . $_SESSION['fname'] . " </a>
</li>
</ul>
</div>";
}
?>
you can use php whitin html
the php code is only considered between php tags so anything else is put directly to browser
as i can see only one part of your html changes so a better design would be
<?php session_start(); ?>
<div id="cssmenu">
<ul>
<li>
<?php if ($_Session['email']=='') {
?>
Registration
<?php }else{ ?>
Greetings -> <?php echo $_SESSION['fname']; ?>
<?php }?>
</li>
</ul>
</div>
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 have a development server for PHP that runs XAMPP. The problem that I have is a parse error. The exact parse error that XAMPP is giving is:
"Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\eifel\title_bar.php on line 4"
I don't see any missing curly braces, nor semi-colons; but there is something that Notepad++ is giving me. There are wavy red lines under the file extension '.php'. The code for the class is below:
The code for the 'title_bar.php' class:
<div>
<?php
if(loggedin()){
<a href='index.php'>Home</a>
<a href='messages.php'>Messages</a>
<a href='logout.php'>Log Out</a>
}else{
echo "Not Logged In";
}
}
<a href='index.php'>Home</a>
<a href='login.php'>Login</a>
<a href='register.php'>Register</a>
</div>
Well that's not PHP. You have PHP and HTML and only PHP code should be between <?php and ?> tags:
<?php
if(loggedin()){
?>
<a href='index.php'>Home</a>
<a href='messages.php'>Messages</a>
<a href='logout.php'>Log Out</a>
<?php
}else{
echo "Not Logged In";
}
?>
<a href='index.php'>Home</a>
<a href='login.php'>Login</a>
<a href='register.php'>Register</a>
</div>
Or similar to what has already been said, you could use:
<div>
<?php
if(loggedin()){
echo "<a href='index.php'>Home</a>
<a href='messages.php'>Messages</a>
<a href='logout.php'>Log Out</a>";
}else{
echo "Not Logged In";
echo "<a href='index.php'>Home</a>
<a href='login.php'>Login</a>
<a href='register.php'>Register</a>";
}
?>
</div>
Make sure you echo or print any HTML elements in PHP otherwise you will get errors as HTML is not 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 8 years ago.
Improve this question
I am trying to create a nav bar where if you are a guest it displays a lock icon and 'Log in' and when you are logged in it displays a lock icon and 'Logout'.
Here is the code for my header:
<section class="top-bar-section">
<ul class="left">
<li><img src="images/icons/home_icon.png"> Home</li>
<li><img src="images/icons/about_icon.png"> About</li>
<li><img src="images/icons/pages_icon.png"> Showcase</li>
<li><img src="images/icons/videos_icon.png"> Videos</li>
</ul>
<ul class="right">
<?php
if (!empty($UserName))
{
echo <li><img src="../images/icons/login_icon.png"> Log in</li>;
}
else
{
echo <li><img src="../images/icons/login_icon.png"> Logout</li>;
}
?>
</ul>
</section>
the section I am working on is under <ul class="right">
and the error I am getting when testing the webpage is
`Parse error: syntax error, unexpected '<' in
C:\wamp\www...\header.php on line 16
PS: Line 16 is where the first 'echo' is
HELP! Please :) Thanks
You need to put the string in the echo statement in quotes (I'd suggest single-quotes, since you've got doubles in the text).
try like this you are missing quote on echo
if (!empty($UserName)) {
echo '<li><img src="../images/icons/login_icon.png"> Log in</li>';
}
else {
echo '<li><img src="../images/icons/login_icon.png"> Logout</li>';
}
The echo requires string like this
echo "Hello World";
So your echo statements must be like this:
echo '<li><img src="../images/icons/login_icon.png"> Log in</li>';
echo '<li><img src="../images/icons/login_icon.png"> Logout</li>';
If you want to use double quotes you should escape quotes that are in the string
echo "\""; /* would echo " */
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So, I've got this bit of code, for which I'm getting the following error.
Parse error, unexpected T_STRING, expecting ',' or ';'
I'm sure this is a very, very simple fix, but I'm still a bit new to the world of PHP. Any thoughts?
echo '
<li>
<a href="'.get_permalink().'">
<img src="'echo get_post_meta(get_the_ID(), 'video_tour_url', true);'">
<div class="galDiv">
<div class="boatTitle">'.get_the_title().'</div>
<div class="boatPrice">'.currency ().$price.'</div>
<div class="boatPower"> '.get_post_meta(get_the_ID(), '_map_ar_address', true).'</div>
</div>
</a>
</li>';
Your problem is with the following code:
<img src="'echo get_post_meta(get_the_ID(), 'video_tour_url', true);'">
Like the rest of your code it should use the concantination operator . and doesn't need an echo statement.
<img src="'.get_post_meta(get_the_ID(), 'video_tour_url', true).'">
You need a period in this code on the third line. and remove the echo:
<img src="'.get_post_meta(get_the_ID()
^
Don't echo HTML. Instead use inline PHP if possible.
<li>
<a href="<?php print get_permalink(); ?>">
<img src="<?php print get_post_meta(get_the_ID(), 'video_tour_url', true); ?>">
<div class="galDiv">
<div class="boatTitle"><?php print get_the_title(); ?></div>
<div class="boatPrice"><?php print currency() . $price; ?></div>
<div class="boatPower"><?php print get_post_meta(get_the_ID(), '_map_ar_address', true); ?></div>
</div>
</a>
</li>
looping? sure.
<?php foreach($widgets as $widget): ?>
<?php endforeach; ?>