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
The simplest question but I can't get it working... What's wrong with the way I'm trying to add an image to this php file?
<?php header("HTTP/1.0 404 Not Found"); ?>
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<h1 class="error"><?php echo t('Page Not Found')?></h1>
<?php echo t('We could not find a page at this address.')?>
<?php if (is_object($c)) { ?>
<br/><br/>
<?php $a = new Area("Main"); $a->display($c); ?>
<?php } ?>
<?php
echo "<img src="img.jpg">"
?>
<?php echo t('Back to Home')?>.
The file named img.jpg sits in the same directory as this .php file. When it runs, I see this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in line 21 where line 21 is echo "<img src="img.jpg">".
instead of :
echo "<img src="img.jpg">";
you can do:
echo "<img src='img.jpg'>";
or
echo '<img src="img.jpg">';
or even escape the quote:
echo "<img src=\"img.jpg\">";
Two, or possibly three, things are wrong with the way you're adding an image.
You need to use different kinds of quotation marks (" vs '), otherwise they cancel each other out.
You need a ; to end the line in PHP
Your image path may be broken. If img.jpg is not in the same directory as the PHP script, it won't work.
Replace:
"<img src="img.jpg"/>"
with
"<img src='img.jpg'/>";
If the problem is with your image path, try using an absolute path (src="http://example.com/your/path/img.jpg") instead of the relative path (src="img.jpg"). If that works, then it means that the relative path was wrong.
You have a wrong quotation on the img line and then I suggest keeping it all in PHP. You can replace your code with this code which is more easy to read and maintain:
header("HTTP/1.0 404 Not Found");
defined('C5_EXECUTE') or die("Access Denied.");
echo '<h1 class="error">'. t('Page Not Found') .'</h1>';
echo t('We could not find a page at this address.');
if (is_object($c)) {
echo '<br /><br />';
$a = new Area("Main");
$a->display($c);
}
echo "<img src='img.jpg'>";
echo ''. t('Back to Home') .'.';
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 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.
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.
Improve this question
I wrote this code
<html>
<head>
<title> page 1</title>
<body>
<style>
a{
margin-left:10px;
}
</style>
<?php
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con,"uoh");
$q = " SELECT * FROM student WHERE id = 201102820" ;
$result = mysqli_query($con , $q ) ;
if($row = mysqli_fetch_array($result)){
if ($row["major"]=="computer engineerig"){
echo "welcome ". $row["name"];
echo '<img src="tran.png"/>';
}
}
?>
</body>
</html>
but when I run it show me like this
Welcome stephen ICON
the icon(picture) that I put comes in front of the text .
Can I do like this
welcome stephen
ICON
I want the icon (picture) comes under the text.
HTML have a tag called Break :) you should echo this :
echo "welcome ". $row["name"];
echo "<br />";
echo '<img src="tran.png"/>';
you need a line break
echo "welcome ". $row["name"] . '<br/>';
echo '<img src="tran.png"/>';
or
echo '</p>' . "welcome ". $row["name"] . '</p>';
echo '<img src="tran.png"/>';
<a> and <img> are inline elements by default. See this article : CSS display: inline vs inline-block
So you have to put the ICON block in a block element to see a separation between the name and the icon.
Like this for example :
if ($row["major"]=="computer engineerig")
{
echo "welcome ". $row["name"];
echo '<p><img src="tran.png"/></p>';
}
Or adding a <br/> like suggested #Noor Adnan
<?php
//here you can add php
?>
<p>welcome <?php echo $row["name"]; ?> </p>
<br />
<img src="tran.png"/>
<?php
// here you can add your php
?>
If you Separate your HTML and PHP then you can easily add css and HTML inside your 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 7 years ago.
Improve this question
I have this code:
?php
if ( is_page('1708')) {
<div id="portofoliu"></div>
}
?>
And this my error:
Parse error: syntax error, unexpected '<' in /home/dacproie/public_html/eventos/wp-content/themes/eventos/header.php on line 141
What is wrong in this code?
Can you help me to solve this problem please?
Thanks in advance!
Missing echo:
<?php
if ( is_page('1708')) {
echo '<div id="portofoliu"></div>';
}
?>
You can't mix HTML and PHP this way.
Another option is (for longer HTML code):
<?php
if ( is_page('1708')) {
?>
<div id="portofoliu"></div>
<?php
}
?>
OR
<?php
if ( is_page('1708')) :
?>
<div id="portofoliu"></div>
<?php
endif;
?>
And, of course, PHP begins with <?php but it seems to be just copy&paste error.
Might seem obvious but... You need to escape your html to be a string. Otherwise PHP trys to execute it.
<?php
if ( is_page('1708')) {
echo '<div id="portofoliu"></div>';
}
?>
You forgot to close and open PHP tags:
<?php
if ( is_page('1708')) {
?>
<div id="portofoliu"></div>
<?php
}
?>
try
<?php
if ( is_page('1708')) {
echo '<div id="portofoliu"></div>';
}
?>
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
My goal is to print all results (fetched from database) and print it according to respective formation.
In html, I could defined it as follows:
<div class="gallery-item category-birds">
<div class="gallery-item-image" style="background-image: url( '_uploads/bc7113a3956b7a45e926f30258fa1b83.jpg' );">
<div class="gallery-item-image-pattern">
<span>Show image</span>
</div>
</div>
<h3>ImageTest1</h3>
<p>MyImageDescription.</p>
</div>
In php, I am trying to print the results in a loop (like I have done before in others examples) but for some reason it's not working.
"animals.php"
<?php
include("../config.php");
$result = mysql_query("SELECT * FROM animals WHERE catid=2 ORDER BY id DESC",$connect);
while($myrow = mysql_fetch_assoc($result))
{//begin of loop
echo "<div class='gallery-item category-birds'>";
echo "<div class=gallery-item-image style='background-image:url(_uploads/bc7113a3956b7a45e926f30258fa1b83.jpg);'>";
echo "<div class=gallery-item-image-pattern>";
echo "<span>Show image</span>";
echo "</div>";
echo "</div>";
echo "<h3> ".$myrow['name']." </h3>";
echo "<p> ".$myrow['description']." </p>";
echo "</div>";
}//end of loop
?>
The index.php includes "animals.php".
The database connection is fine, because by accessing "animals.php" I have the content desired.
The index.php have css linked, where is defined the classes and others.
I have tried to replace inside of those echo's: " for \". -> Not working.
I have tried to replace inside of those echo's: " for '. -> Not working.
Could you help me? Iam out of ideas how to solve this.
Thanks and regards,
RMC
FIrst there is no issue with the MySQL if you can access the page and it works. The issue is when you include it in another page. The issue that comes to mind is if animals.php is located in a folder, example: /inc/. Your config.php and index.php are located in your docroot(/). This may cause a relative issue in loading the config.php file, because it may be looking out of your docroot. I would check your error.log on your server to verify this. I normally in any templated PHP website that I have created, my config.php file would be included in index.php since it would be used by the whole site.
A few potential solutions:
check your error.log to make sure it is finding the config.php file in the right location
move your include for config.php to index.php
read up on php templating, example tutorial - http://chadminick.com/articles/simple-php-template-engine.html
You're missing some single quotes around your class name of div 2 and 3
<?php
include("../config.php");
$result = mysql_query("SELECT * FROM animals WHERE catid=2 ORDER BY id DESC",$connect);
while($myrow = mysql_fetch_assoc($result))
{//begin of loop
echo "<div class='gallery-item category-birds'>";
echo "<div class='gallery-item-image' style='background-image:url(_uploads/bc7113a3956b7a45e926f30258fa1b83.jpg);'>";
echo "<div class='gallery-item-image-pattern'>";
echo "<span>Show image</span>";
echo "</div>";
echo "</div>";
echo "<h3> ".$myrow['name']." </h3>";
echo "<p> ".$myrow['description']." </p>";
echo "</div>";
}//end of loop
?>
(P.s. I also assume that you make your connection with the database in your config.php file,
what makes that you don't need to put your $connect variable in the mysql_query() function.
$result = mysql_query("SELECT * FROM animals WHERE catid=2 ORDER BY id DESC");
)
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 trying to display a "log in" / "log out" link. I want to display the log in link if they are not logged in, etc. I'm having trouble getting this to work. Heres what I've been trying:
<?php if (isset($_SESSION['access_token']))
{ ?> Log out<?php } ?>
<?php
else
{ ?> Log In <?php } ?>
Basically, if the assess_token is set, it will show a link to log out. And if not, a log in link. I keep getting this as an error:
Parse error: syntax error, unexpected T_ELSE
And i've tried this variation:
<?php if (isset($_SESSION['access_token']))
{ echo "Log out" }
else
{ echo "Log In" } ?>
which get me:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
what am i missing here?
You have 2 examples and both have syntax errors:
Parse error: syntax error, unexpected T_ELSE
If you format your code correctly, you found the error:
<?php
if (isset($_SESSION['access_token'])) {
?> Log out<?php
} else {
?> Log In <?php
}
?>
That:
<?php } ?>
<?php
else
{ ?>
is not valid. The PHP intepreter can't handle this! Please use <?php } else { ?>
The second: Use an Syntax-Highlighted editor! You see that the Syntax is not correct.
Escape the " in your code, you forgotten the ; after the echo:
<?php
if(isset($_SESSION['access_token'])) {
echo "Log out";
} else {
echo "Log In";
}
?>
It's normal . look at your echo . There are only double quotes. You have to use (for example) double quotes for echo, and single quotes to delimit logout.php and login.php
echo "<a href='logout.php'>Log out</a>";
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
It's been a long time since I have done php so sorry for the silly question.
This is my current code, I'm trying to save the URL as a variable so that I can insert it into the echo, but it doesn't seem to work as nothing appears:
<?php ob_start();
echo get_post_meta($post->ID, 'oldurl', true);
$old_url = ob_get_contents();
ob_end_clean();
?>
<?php echo do_shortcode('[fbcomments][fbcomments url="$old_url" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
I have echoed $old_url and can see that it has the correct value, but how do I insert the value into the echo do_shortcode with url="$old_url"?
This doesn't work either:
<?php echo do_shortcode('[fbcomments][fbcomments url="echo $old_url;" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
You'll need to switch your quotes around. Single quotes print everything out as-is. Double-quotes will process the variables. Also, echo is not needed within an echo.
<?php echo do_shortcode("[fbcomments][fbcomments url='$old_url' width='375' count='off' num='3' countmsg='wonderful comments!']"); ?>
Another way to do it without switching your quotes is to break out of the statement:
<?php echo do_shortcode('[fbcomments][fbcomments url="'.$old_url.'" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Variables are not replaced in single quotes ...
<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Singles quotes doesn't allow variables parsing.
For example :
$var = 'Hello';
echo 'The content of my var is : $var';
// Will output : "The content of my var is : $var"
echo "The content of my var is : $var";
// Will output : "The content of my var is : Hello"
So you have to use double quotes or use the concatenate operator : .