Unexpected T_ECHO, expecting ',' or ';' [closed] - php

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; ?>

Related

Can someone explain this PHP code? [closed]

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
<h1 class="site-title">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
rel="home"><?php bloginfo( 'name' ); ?>
</a>
</h1>
if (is_category('Ponies')) { ?>
// overlay a pretty rainbow on the logo for the ponies category
<img id="rainbow"
src='<?php bloiginfo('template_directory');?>/img/rainbow.png"
alt="OMG! Ponies! " />
<?php } ?>
I'm having trouble matching the PHP tags. The comment for the code says "Now any time the category of the content is Ponies, your header also includes the rainbow.png." But it's clear how that is happening. The actual code is on p245 of WordPress Design and Developement by Williams. Thanks for putting another pair of eyes on it.
"If" is not inside <?php ... ?>. Must be:
<?php if (is_category('Ponies')) { ?>
I prefer to use <?php if (condition): ?> when there's HTML in-between.
But anyhow...
1) The if() statement needs to be inside php tags.
2) You don't need echo to retrieve the bloginfo.
bloginfo() documentation
3) You've misspelled bloginfo at the bottom...
My code:
<h1 class="site-title">
<a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
<?php $bloginfo('name'); ?>
</a>
</h1>
<?php if (is_category('Ponies')) : ?>
<img id="rainbow"
src="<?php get_bloginfo('template_directory') . '/img/rainbow.png'; ?>"
alt="OMG! Ponies!" />
<?php endif; ?>

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\eifel\title_bar.php on line 4 [closed]

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.

Code not working in PHP if else statement [closed]

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 " */

php , is it variable or constant [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i want to add li element to this page,
this website was done by someone else
the index.php file include several php files, along with them main.php.
this is the code for main.php
<div class="center"><p class="text3"><?php echo LABEL_TXT_FORNT_PAGE_TITLE;?></p>
<div class="netw"><div>
<div class="title"><?php echo LABEL_TXT_KDMATY;?></div></div>
<p><img src="img/<?php echo $dir;?>/1.jpg" border='1' alt="img" /></p>
<p class="text1"><?php echo TXT_CONTANT_FOR_KDAMATY;?> </p>
<p class="text2"></p>
</div>
<div class="suppserv"><div>
<div class="title"><?php echo LABEL_TXT_CHECK_PRINTING;?></div></div>
<p><img src="img/<?php echo $dir;?>/2.jpg" border='1' alt="img" /></p>
<p class="text1"><?php echo TXT_CONTANT_FOR_PRINT;?>
</p>
<p class="text2"></p></div>
<div class="remote"><div>
<div class="title"><?php echo LABEL_TXT_POINT_OF_SALES;?></div></div>
<p><img src="img/<?php echo $dir;?>/3.jpg" border='1' alt="img" /></p>
<p class="text1"><?php echo TXT_CONTANT_FOR_SALES;?></p>
<p class="text2"></p></div>
</div>
<div class="line"><img src="img/12.png" alt="img" /></div>
<div class="center2">
<div class="netw">
<p class="text4"><?php echo LABEL_TXT_EXPER;?></p>
<p class="text5"><?php echo TXT_CONTANT_EXPER;?></p>
<ul>
<li><?php echo UL_EXPER_EX1;?></li>
<li><?php echo UL_EXPER_EX2;?></li>
<li><?php echo UL_EXPER_EX3;?></li>
<li><?php echo UL_EXPER_EX4;?></li>
<li><?php echo UL_EXPER_EX5;?></li>
</ul>
<p class="text2"><a href="<?php echo SITE_URL; ?>/expertise.php"><?php echo
LABEL_TXT_MORE_LINKS;?><img alt="img" src="img/<?php echo $dir;?>/11.png"></a></p>
<div class="clear"></div>
</div>
<div class="remote">
<p class="text4"><?php echo LABEL_TXT_CUSTOMER;?></p>
<p class="text5"><?php echo TXT_CONTANT_CUSTOMER;?></p>
<ul>
<li><?php echo UL_CUSTOMER_EX1;?></li>
<li><?php echo UL_CUSTOMER_EX2;?></li>
<li><?php echo UL_CUSTOMER_EX3;?></li>
<li><?php echo UL_CUSTOMER_EX4;?></li>
<li><?php echo UL_CUSTOMER_EX5;?></li>
</ul>
</div>
<div class="suppserv">
<p class="text4"><?php echo LABEL_TXT_OUR_SERVICES;?></p>
<p class="text5"><?php echo TXT_CONTANT_SERVICES;?></p><br />
</div>
</div>
note this line :
<li><?php echo UL_CUSTOMER_EX1;?></li>
can someone explain to me what is this, it is not variable and not a constant, so what is it ?
You can define constants in php like this
define("MY_VARIABLE", 6)
And then access anywhere on the script:
echo MY_VARIABLE; // print 6
Is the same that LABEL_TXT_OUR_SERVICES
This is a constant, note that it hasn't the dollar sign before.
Refer to this http://php.net/manual/pt_BR/function.define.php
That constant was declared by using
define("UL_CUSTOMER_EX1", 'some_value_or_var');
Variables' first character is $ sign in PHP.
$var1 = 0; //this is a variable
define('CONST', 100); // is a constant
You can use $var1 and CONST in the page with one difference: $var1's value may be changed programatically but constansts no. Value of CONST cannot change during the execution of the script
That there is a constant. It must have been define()'d somewhere previously, possibly in an included file.
If I were you, I'd search for any define() statements that contain UL_CUSTOMER_EX1.
Yes, i agree with everybody else's opinion: it's a constant defined inside one of the included files.
BUT!
There might be another possibility, which may be probable if the original author is a novice developer:
an UNDEFINED constant, being treated as a string by default from php without warnings enabled.
Because, in PHP, if you use a constant which is undefined, it is reverted to a string which contains the constant name (eg: UNK_CONST becomes the string "UNK_CONST"). Of course it gives a warning too, but warnings may have been suppressed.

delete page is not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am creating a cms and have set up all the pages perfectly but the delete page.
I have this code for my delete.php:
<?php
session_start();
include_once('../include/connection.php');
include_once('../include/article.php');
$article = new Article;
if (isset($_SESSION['logged_in'])) {
$articles = $article->fetch_all();
?>
<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="../style.css" />
</head>
<body>
<div class="container">
CMS
<br /><br />
<form action="delete.php" method="get">
<select onchange="this.form.submit();">
<?php foreach ($articles as $article){ ?>
<option value="<?php echo $article['article_id']; ?>"><?php echo $article['article_title']; ?></option>
<php } ?>
</select>
</form>
</div>
</body>
</html>
<?php
} else {
header('Location: index.php');
}
?>
But in my error log It is telling me this:
PHP Parse error: syntax error, unexpected T_ELSE in /delete.php on line 37
Line 37 is "} else {" please can someone advise me as to where I am going wrong?
thank you.
Your php opening tag is invalid. Change
< php } ?>
to
<?php } ?>

Categories