View Full Version : Include an image in PHP
Jack!
02-06-2010, 07:06 PM
Im slowly learning diffrent things about php, and my website is coded in PHP, i was just wondering how i would go about including an image. i take it its diffrent from HTML, because that throws up errors at me :rolleyes:
Ive also tried PHPInclude, no luck there either, please help! :S
Blinger$
02-06-2010, 07:09 PM
what?
Wouldn't you just echo the image?
<?php
echo("<img src='link/to/image.png'>");
?>
Jack!
02-06-2010, 07:19 PM
what?
Wouldn't you just echo the image?
<?php
echo("<img src='link/to/image.png'>");
?>
Parse error: syntax error, unexpected T_STRING in ******/public_html/home/pj.php on line 7
+Rep anyway for helping :)
Blinger$
02-06-2010, 07:20 PM
what is your total source code?
Parse error: syntax error, unexpected T_STRING in ******/public_html/home/pj.php on line 7
+Rep anyway for helping :)
<?php
echo "<img src='link/to/image.png'>";
?>
Remove the brackets from the echo tag
As a side note,
echo " You can't use any speech marks here in between the two end speech marks of the echo you need to use single quotes here ";
echo ' If you do need to use any double quotes, use single quotes at the end, but that means you can use single quotes in the echo ';
Probly confused you that though haha
Jack!
02-06-2010, 07:28 PM
Ijoe, thanks but no luck +rep
Index.php
<?php
switch($_GET['p']){
default:
// Index page
$pageTitle="Welcome to ItsJack";
$pageContent="Erm, use the links above"
."<br />";
break;
case "about":
$pageTitle="About this site";
$pageContent="Made by ...";
break;
}
include("inc.php");
?>inc.php
<?php if($pageTitle==""&&$pageContent=="") die(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>ItsJack<?php echo ($pageTitle!="" ? " - ".strip_tags($pageTitle) : ""); ?></title>
<link rel="stylesheet" href="src/style.css" type="text/css" media="screen" title="main" charset="utf-8">
</head>
<body>
<div class='maindiv'>
<div class='top'></div>
<div class='nav'>
<a class='navitem' href='index.php'>Home</a>
<a class='navitem' href='pj.php'>Projects</a>
<a class='navitem' href='dl.php'>Downloads</a>
<a class='navitem' href='tools'>Tools</a>
</div>
<div class='content'>
<div class='title'><?php echo $pageTitle; ?></div>
<?php echo $pageContent; ?>
</div>
</body>
Ijoe, thanks but no luck +rep
Index.php
<?php
switch($_GET['p']){
default:
// Index page
$pageTitle="Welcome to ItsJack";
$pageContent="Erm, use the links above"
."<br />";
break;
case "about":
$pageTitle="About this site";
$pageContent="Made by ...";
break;
}
include("inc.php");
?>inc.php
<?php if($pageTitle==""&&$pageContent=="") die(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>ItsJack<?php echo ($pageTitle!="" ? " - ".strip_tags($pageTitle) : ""); ?></title>
<link rel="stylesheet" href="src/style.css" type="text/css" media="screen" title="main" charset="utf-8">
</head>
<body>
<div class='maindiv'>
<div class='top'></div>
<div class='nav'>
<a class='navitem' href='index.php'>Home</a>
<a class='navitem' href='pj.php'>Projects</a>
<a class='navitem' href='dl.php'>Downloads</a>
<a class='navitem' href='tools'>Tools</a>
</div>
<div class='content'>
<div class='title'><?php echo $pageTitle; ?></div>
<?php echo $pageContent; ?>
</div>
</body>
Try putting { } brackets around the
$pageContent and $pageTitle
So it'll be {$pageContent} and {$pageTitle}
Jack!
02-06-2010, 07:34 PM
Try putting { } brackets around the
$pageContent and $pageTitle
So it'll be {$pageContent} and {$pageTitle}
why? the code works fine??
Blinger$
02-06-2010, 07:35 PM
where are you trying to include the image?
Oh sorry I thought you were having problems with them pages, ignore that then
Paste the code you currently have on pj.php (:
Jack!
02-06-2010, 07:47 PM
pj.php (Projects) The image needs to go on this page, could be muliple images
<?php
switch($_GET['p']){
default:
// Index page
$pageTitle="Projects";
$pageContent="My Past and Present projects are listed here<br><br>IMAGE HERE"
."<br />";
break;
case "about":
$pageTitle="About this site";
$pageContent="Made by ...";
break;
}
include("inc.php");
?>
Blinger$
02-06-2010, 07:48 PM
the code works fine :S?
Jack!
02-06-2010, 07:50 PM
the code works fine :S?
Yeah it does, why shouldnt it :P
Yeah it does, why shouldnt it :P
Because you said it didnt lmao
Jack!
02-06-2010, 07:57 PM
Oh wait, were it says image here is were i need the image include code :D the code i have been given so far in this thread havnt worked, so i just put image here, sorry for any confusion!
Blinger$
02-06-2010, 08:03 PM
<?php
switch($_GET['p']){
default:
// Index page
$pageTitle="Projects";
$pageContent="My Past and Present projects are listed here<br><br><img src='test.jpg'>"
."<br />";
break;
case "about":
$pageTitle="About this site";
$pageContent="Made by ...";
break;
}
include("inc.php");
?>
works fine for me :s
Jack!
02-06-2010, 08:07 PM
<?php
switch($_GET['p']){
default:
// Index page
$pageTitle="Projects";
$pageContent="My Past and Present projects are listed here<br><br><img src='test.jpg'>"
."<br />";
break;
case "about":
$pageTitle="About this site";
$pageContent="Made by ...";
break;
}
include("inc.php");
?>
works fine for me :s
That worked! i have no idea why it didnt before, Thanks! i must of done something wrong in the code -.-
Oh right lol
it didnt work coz we were giving you the full thing thinking you were just having it on its own haha
glad it's fixed now though (:
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.