I am trying to figure out why I'm getting this error
"Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/idgcca/public_html/web-design-samples-testing.php on line 64"
echo '
<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"><a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title='<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>';" onmouseout="this.title='';" href="'. $post->url . '">
<img src="' . $post->thumb . '" border="0"/></a> <div class="design-sample-txt">'. $post->author.'</div></div>
';
im a PHP newb just trying to understand it on my own but my head is turning. A help would be pretty much appreciated...
here is your problem:
this.title='<
you should escape this quote. and the one at the closing a tag too. like this:
echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;">
<a rel="lightbox[web]" title="'. $post->title .'"
onmousedown="this.title=\'<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';"
onmouseout="this.title=\'\';" href="'. $post->url . '">
<img src="' . $post->thumb . '" border="0"/></a>
<div class="design-sample-txt">'. $post->author.'</div>
</div>';
You have an unterminated string on that line. You should escape your quotes with a slash like this \"
echo "<div style=**\"**float:left;.....";
You need to escape single-quotes in a single-quote-string.
echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"><a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title=\'<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';" onmouseout="this.title=\'\';" href="'. $post->url . '">';
I would advise you to split your code in multiple lines for readability.
It'll help to debug this kind of line.
Take a look at the echo operator examples
To answer to your question, there are some quotes misused in your code. You need to escape them.
echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;">
<a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title=\'<a
target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';"
onmouseout="this.title=\'\';" href="'. $post->url . '"><img src="' . $post->thumb . '"
border="0"/></a> <div class="design-sample-txt">'. $post->author.'</div></div>';
Assuming you pasted the code exactly, the first error is right at the beginning, when you end the first quote. It expects that to read:
echo ' title .';
The two quotes next to each other don't make any sense.
You got your answer from SilentGhost.
I would use HEREDOC for such things.
You should use htmlspecialchars on those attribute values:
function html($str, $charset=null) {
if (!is_null($charset)) {
return htmlspecialchars($str, ENT_QUOTES, $charset);
} else {
return htmlspecialchars($str, ENT_QUOTES);
}
}
echo '
<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;">
<a rel="lightbox[web]"
title="' . html($post->title) . '"
onmousedown="' . html('this.title=\'<a target="_blank" href="http://www.google.ca/">Google</a>\'') . '"
onmouseout="' . html('this.title=""') . '"
href="' . html($post->url) . '">
<img src="' . html($post->thumb) . '" border="0"/></a>
<div class="design-sample-txt">' . html($post->author) . '</div>
</div>
';
Related
I was working on my term project i fetched data from api and print with php on my html page but after adding my php codes, my main headers are looks broken in the picture below.
So i tried many times to fix this problem using some other divs, make some changes on my css file etc. but still the same result.
here is my code:
<div class="topRated">
<h1>Top Rated Movies</h1>
<?php
//echo ' <h1>Top Rated Movies</h1>';
$id_movie = urlencode("id");
$data = file_get_contents("https://api.themoviedb.org/3/movie/top_rated?api_key=59419be18ecb300104521be9c3837f01&language=en-US&page=1");
$data = json_decode($data,true);
foreach($data['results'] as $result){
echo '<div class="column">
<div class="row">
<img src="'."http://image.tmdb.org/t/p/w500".''. $result['poster_path'] . '" width="140" height="180"><h4><span style="color:#000000;text-align:center;">' . $result['original_title']. "</h4><h5><span style=color:#000000;text-align:center;>"." Rate : " . $result['vote_average'] . " | Vote : " . $result['vote_count'] ."</h5> </h6><span style=color:#000000;text-align:center;>"."Popularity : " . round($result['popularity']) . "</h6>
</div>
</div>";
}
?>
</div>
<div class="popular">
<h1>Popular Movies</h1>
<?php
//echo '<h1>Popular Movies</h1>';
$id_movie = urlencode("id");
$data = file_get_contents("https://api.themoviedb.org/3/movie/popular?api_key=59419be18ecb300104521be9c3837f01&language=en-US&page=1");
$data = json_decode($data,true);
foreach($data['results'] as $result){
echo '<div class="column">
<div class="row">
<img src="'."http://image.tmdb.org/t/p/w500".''. $result['poster_path'] . '" width="140" height="180"><h4><span style="color:#000000;text-align:center;">' . $result['original_title']. "</h4><h5><span style=color:#000000;text-align:center;>"." Rate : " . $result['vote_average'] . " | Vote : " . $result['vote_count'] ."</h5> </h6><span style=color:#000000;text-align:center;>"."Popularity : " . round($result['popularity']) . "</h6>
</div>
</div>";
}
?>
</div>
<div class="upcoming">
<h1>Upcoming Movies</h1>
<?php
//echo '<h1>Upcoming Movies</h1>';
$id_movie = urlencode("id");
$data = file_get_contents("https://api.themoviedb.org/3/movie/upcoming?api_key=59419be18ecb300104521be9c3837f01&language=en-US&page=1");
$data = json_decode($data,true);
foreach($data['results'] as $result){
echo '<div class="column">
<div class="row">
<img src="'."http://image.tmdb.org/t/p/w500".''. $result['poster_path'] . '" width="140" height="180"><h4><span style="color:#000000;text-align:center;">' . $result['original_title']. "</h4><h5><span style=color:#000000;text-align:center;>"." Rate : " . $result['vote_average'] . " | Vote : " . $result['vote_count'] ."</h5> </h6><span style=color:#000000;text-align:center;>"."Popularity : " . round($result['popularity']) . "</h6>
</div>
</div>";
}
?>
</div>
Also my css codes are in below:
.column {
height: 340px;
margin-top: 70px;
margin-left: 45px;
float: left;
width: 13%;
padding: 0px;
font-family: serif;
font-style: normal;
text-align: center;
display: inline;}
.row::after {
margin-left: 40px;
font-family: serif;
font-style: normal;
text-align: center;}
I didn't write any css codes for the div outside of the php codes. But i can't fix this problem.
How can i fix this?
In my code, I have a center tag and have styled the center tag so it looks the way I want it to look. It currently looks like this:
Whenever I go on my admin account (one that has a different user id than the normal users) it looks way different than if a regular user would see it. It looks like this:
I would like to know if there is any way around this so it looks the same as if a regular would see it on an admin account.
I've tried putting a div tag around it and using the same styling features, but that didn't work. I've tried putting the center tag around different parts of the code, but since it's an "if" statement, it will look different.
Here is the code:
<style>
center{
border-left: .17em dashed;
border-top: .17em solid;
border-right: .17em dashed;
border-bottom: .17em solid;
padding-left:25px;
padding-bottom: 20px;
width: 1000px;
background-color: #E1A0A0;
border-color: black;
margin: auto;
text-align: left;
}
</style>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<center><b><h2>' . $row['title'] . '</h2></b>' . $row['post'] . '<br/><br/> <b>Posted On: </b>' . $row['postdate'] . '<br/>View Post Comments | ';
if($_SESSION['user_id'] == 3) {
echo '<a href="update.php?id=' . $row['blogid'] . '" >Update Blog Post</a> | <a href="' . basename(__FILE__) . '?id=' . $row['blogid'] . '" >Delete Blog Post</a></center>';
}
}
?>
I know that I can't just put another center tag around the
"echo '<center><b><h2>' . $row['title'] . '</h2></b>' . $row['post'] . '<br/><br/> <b>Posted On: </b>' . $row['postdate'] . '<br/>View Post Comments |';"
part of the code and
"echo '<a href="update.php?id=' . $row['blogid'] . '" >Update Blog Post</a> | <a href="' . basename(__FILE__) . '?id=' . $row['blogid'] . '" >Delete Blog Post</a></center>';"
part of the code because it will look like this:
Additionally, if I put the center tag around everything, it will look like this:
I just want to make it look the same no matter who views it.
after the close of the if(){} you need to echo '</center>' and remove it from inside the if(){}. You have setup a loop where sometimes center is not closed
echo '<center><b><h2>' . $row['title'] . '</h2></b>' . $row['post'] . '<br/><br/> <b>Posted On: </b>' . $row['postdate'] . '<br/>View Post Comments | ';
if($_SESSION['user_id'] == 3) {
echo '<a href="update.php?id=' . $row['blogid'] . '" >Update Blog Post</a> | <a href="' . basename(__FILE__) . '?id=' . $row['blogid'] . '" >Delete Blog Post</a>';
}
echo '</center>';
Not sure if I quite understand what is being asked for, but if all you want to do is make everything look like the last image you posted, remove this in the css:
padding-left:25px;
$content = '<div id="contact" style="display:''; border-radius: 5px; padding: 20px;" class="center"><br><!--Spacing--><br><!--Spacing--></div>
<div id="contact" style="display:''; border-radius: 5px; background-color: #EBEBEB; padding: 20px;" class="center">
<form>
<center><h4><b>' . $_POST['email1'] . " " . $_POST['email2'] . '</b></h4></center>
<br><!--Spacing-->
<center>' . $_POST['email4'] . '<center>
<br><!--Spacing-->
<center>' . $_POST['email3'] . '<center>
<br><!--Spacing-->
<center>' . $_POST['email5'] . '<center>
<br><!--Spacing-->
<center><img src="rushforms/profile_images/' . $_POST['file_number'] . '.png"/></center>
<center><img src="rushforms/profile_images/' . $_POST['file_number'] . '.jpg"/></center>
<center><img src="rushforms/profile_images/' . $_POST['file_number'] . '.gif"/></center>
</form>
</div>';
How can I set all of this to $content?
I was under the impression that ' ' could be used to set html code to a variable in php.
It will work but when you have such content it can be easier to use heredoc or nowdoc syntax .
It will avoid all that concatenations.
//top of the code just consists of an if statement and some code.
case 'itemimage' :
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href=' . <?php grab_item_image(); ?> . "</div>"';
break;
}
}
That was my attempt but it does not look rite on my text editor. I am also using inline-css not sure if that matters.
The only thing that i'm trying to echo out is this div with the function providing an href.
<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href="#thephpfunctionhere"</div>
It's kind of confusing me with all the single and double quotes.
Quotes Problem and you started <?php again. Use the code below
//top of the code just consists of an if statement and some code.
case 'itemimage' :
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . grab_item_image() . '" /></div>"';
break;
}
}
Hope this helps you
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . <?php grab_item_image(); ?> . '"></div>"';
The image needs the ''SRC'' attribute instead of href. Also, since you are echo-ing within a php-tag you don't have to open the <\?php again but directly refer to the function.
echo
'<div class="product-preview-image" style="background: red; height:75px; width:75px;">' ,
'<img src="' . grab_item_image() . '" />' ,
'</div>"';
Komma's are even faster when using a direct echo. Not suitable for assigning it to a $variable
is there something wrong from with my code? something hidden quote i forgot to close.
{
echo '<div class="project_box" title="'. $row['title']. '">';
echo '<p class="project_title">' . $row['title'] . '</p>';
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200"</img>';
echo '</div>';
}
when i echo this in my project box it has some space between the bottom of the image, and the bottom border i give to the div. i give the box a height "auto".
this is the div i place the echo'ed stuff in;
.project_box{
float:left;
width: 200px;
height: auto;
border: 1px solid #dbae78;
opacity: 0.7;
}
i cant find the problem:( i hope you see the problem in my code what i didn't see atm.
i want the border sticks to the bottom of the image.
It looks like
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200"</img>';
Should be
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200" />';
The img tag is a self closing tag, meaning it won't have a <img> and a </img>, only a <img/>. Also, even if it did, you still didn't have the closing bracket on the beginning of the tag.