This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Im trying to echo the content of the foreach loop inside div tag but I get an error message. I know my making a mistake in concatenating html and php but Im not sure where I'm making the mistake. Can some one point me in the right direction?
<php
for($i=0; $i<$daysInTheMonth; $i++){
if($i==$firstDayOfMonth)
$BeginMonth= true;
if($BeginMonth){
$CounterForDays++;
echo "<div class=dateContainner> ".$CounterForDays <br/> ;
foreach ($_POST['mondayTime'] as $Times ){
echo "$Times <br>" ;
}
."</div>";
}
else
echo "<div class=dateContainner> </div>";
}
?>
Use this code
if($BeginMonth){
$CounterForDays++;
echo "<div class=dateContainner> ".$CounterForDays." <br/>" ;
foreach ($_POST['mondayTime'] as $Times ){
echo $Times."<br>" ;
}
echo "</div>";
}
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am trying to echo multiple images but i get the error:
"PHP Parse error: syntax error, unexpected '?>' in
/public_html/View/Pages/Home.php on line 17".
Can you give me any guidance on how to fix it? code below
<?php
for($i=0;$i<$length;$i++) {
echo ?><img class="meme-image" src="<?php $meme["$imd_id" == "$i"]->$path?>"><?php
}
?>
Try By this.
<?php
for($i=0;$i<$length;$i++) {
echo '<img class="meme-image" src='.$meme[$imd_id == $i]->$path.' ">';
}
?>
Note : You do not require to close php tag. instead of that insert this in php echo.and also you must read this For best practice.
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:
Reference - What does this error mean in PHP?
(38 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
for my issue i'll try to be as brief as possible
what am trying to do is reference a page with a specific id in the HTML anchor link with PHP as the below
<body>
<?php $linkName = "Second Page"; ?>
<?php $id = 5; ?>
<?php echo $linkName?><br>
and it works fine
now what am trying to do is to make the $id part more dynamic by making looping the number from 1 to 10 and also providing 10 links
the code is
</head>
<body>
<?php $linkName = "Second Page"; ?>
<?php $id = 5; ?>
<?php
for ($i=0; $i < 10 ; $i++) {
echo "<a href='secondPage.php?id=<?php echo $i;?'>Link1</a>";
};
?>
</body>
however what i did notice as the below images indicates when i hover on the links i noticed that i refer to a strange link
and when i cliched on it it takes me to the following link with an id that i did not want as below
http://localhost/PHP_Course/secondPage.php?id=%3C?php%20echo%201;?
i tried researching the subject and i tried escaping the quotation but it does not seem to resolve the problem
Any help please ??
<?php and ?> tags indicate to the PHP preprocessor that anything inside them is code and needs to be parsed, everything outside is just text PHP doesn't touch.
Inside the <?php tag, "<?php" string has no special meaning, so is printed. You do not need to open and close tags all the time, try this:
</head>
<body>
<?php
$linkName = "Second Page";
$id = 5;
for ($i = 0; $i < 10 ; $i++) {
echo "<a href='secondPage.php?id=$i;'>Link1</a>";
};
?>
</body>
You're echoing a string in PHP, and using <?php... inside that string.
Solution:
echo "<a href='secondPage.php?id=" . $i . "'>Link1</a>";
id=$i will also work, because you can include variables directly in double-quoted strings.
You're echoing the PHP code itself as a string. You don't need to put PHP code inside of PHP code. Just concatenate the values you want to echo:
echo 'Link1';
because you already started an echo statement so you don't need to add another PHP starting and ending tags. just check my code below and try it.
<?php
for ($i=0; $i < 10 ; $i++) {
echo "<a href='secondPage.php?id=".$i."'>Link1</a>";
} ;
?>
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> ";}