unexpected endif line 34 don't know why [closed] - 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
parse error unexpected endif at line i don't know why
<form name="contactform" method="post" action="check.php" class="form-horizontal" role="form">
<?php if(array_key_exists('errors', $_SESSION)); ?>
<div class="alert alert-danger">
<?php implode('<br>', $_SESSION['errors']); ?>
</div>
<?php unset($_SESSION['errors']); ?>
<?php endif;?>

Change
<?php if(array_key_exists('errors', $_SESSION)); ?>
to:
<?php if(array_key_exists('errors', $_SESSION)): ?>
Reference
Explanation:
In your code, you are putting semi-colon ; after if statement.
It means you are closing if control structure, hence, endif below has no meaning.
If you put :, the code between if and endif will be considered as body of control structure and hence will not produce error.

Related

What is wrong with this code PHP [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
I have this code :
<div class="gigel"><?php
// In case there is opening and closing shortcode.
echo do_shortcode('[woocs show_flags=1 width='300px' flag_position='right']');
?></div>
This is shortcode:
[woocs show_flags=1 width='300px' flag_position='right']
This is the error:
Parse error: syntax error, unexpected '300' (T_LNUMBER) in /home/dacproie/public_html/test2/wp/wp-content/themes/mix/header.php on line 189
How can I solve this problem?
Thanks in advance!
just change below code with
<div class="gigel"><?php
// In case there is opening and closing shortcode.
echo do_shortcode("[woocs show_flags=1 width='300px' flag_position='right']");
?></div>
i hope this is working for you.
please, try to clean your code
<?php
$forHtml = do_shortcode("[woocs show_flags=1 width='300px' flag_position='right']");
?>
<!-- separate your layers -->
<div class="gigel"><?php
<?php print ("%s", $forHtml); ?>
?></div>
Always try to use double quotes when you have to use do_shortcode() function.
So use of double quotes instead of single quotes fix your problem and you need to modify it as like :
<div class="gigel">
<?php
echo do_shortcode("[woocs show_flags=1 width='300px' flag_position='right']");
?>
</div>

String PHP Spell Wrongly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
PHP spelling frustrated me. I keep trying to add ". ABC ." and '. ABC .'. But it still doesnt work. Like my code below:
echo '
<div class="box">
<p> '.$obj->name.': "'.$obj->message.'" </p>
<p class="right"> '.date_format('.$obj->message_date.', 'Y-m-d H:i:s');.' </p>
</div>
';
The problem is DATE FORMAT doesn't want to show on a webpage. Any idea?
Change
'.date_format('.$obj->message_date.', 'Y-m-d H:i:s');.'
to
'.date_format($obj->message_date, 'Y-m-d H:i:s').'
If $obj->message_date is a string, you need to convert it to a date object first:
'.date_format(date_create($obj->message_date), 'Y-m-d H:i:s').'
The issue you are having is you are not concatenating your PHP into your string correctly.
echo '
<div class="box">
<p> '.$obj->name.': "'.$obj->message.'" </p>
<p class="right"> '.date_format($obj->message_date, "Y-m-d H:i:s").' </p>
</div> ';
I think this should not provide errors on that front. If the page still doesn't load you will need to look at the $obj to see if there is actually a message_date property and that is a date.
For more information see http://php.net/manual/en/language.operators.string.php

$_GET . Undefined Variable. Cant find solution [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'm having an issue and am out of ideas.
I'm trying to get a parameter from the URL, but PHP insists in saying that the variable is not defined.
The URL is
http://localhost/trendwatcher/index.php?date=2014-10-18
And the script is something like
<?php include "header.php"; ?>
<section id="stats">
Showing trends for <?php echo $GET_["date"]; ?>
</section>
And finally, the error:
Showing trends for
Notice: Undefined variable: GET_ in C:\xampp\htdocs\trendwatcher\index.php on line 4
Does anyone have any ideas?
Thanks!
Fix your code from:
<section id="stats">
Showing trends for <?php echo $GET_["date"]; ?>
</section>
to
<section id="stats">
Showing trends for <?php echo $_GET["date"]; ?>
</section>

Error PHP Twitter share [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 problem with this code:
<?php echo 'Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>'; ?>
I get the error:
Parse error: parse error, expecting ','' or';''
You either need to escape all of the single quotes in that string or don't use PHP to output that code (recommended):
<?php
//some php code
?>
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?''http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<?php
// more PHP code
?>
Escaped quotes:
<?php echo 'Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\'://platform.twitter.com/widgets.js\';fjs.parentNode.insertBefore(js,fjs);}}(document, \'script\', \'twitter-wjs\');</script>'; ?>

Getting a Parse error: syntax error, unexpected '}', expecting ',' or '; [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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
Improve this question
Here is my code. I'm new to php and just trying to edit a page using Kompozer. When I published the site back to the ftp server this error suddenly appeared on the page. Odd since I didn't even touch this code. (I have since touched the below code trying to fix it). Any help fixing this code would be much appreciated.
<?php
if(isset($_SESSION["pkg_error"]))
?>
<div class="error_msg_cont">
<?php
foreach($_SESSION["pkg_error"] as $error)
{
echo $error. "<br>"
}
?></div>
<?php
if(isset($_SESSION["msg"]))
{
echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>'
}
?>
On these two lines:
echo $error. "<br>" }
echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>' }
You need a semicolon before the closing }.
Closing a PHP code block (?>) implies a semicolon, but closing a block of code within a PHP code block (}) does not.
you missed ; on :
echo $error. "<br>" }
and
echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>' }
Actually, the error is self-explained.

Categories