Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Thumbs up Include an image in PHP

    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

  2. #2
    Join Date
    Sep 2005
    Posts
    888
    Tokens
    177

    Latest Awards:

    Default

    what?

    Wouldn't you just echo the image?
    PHP Code:
    <?php
    echo("<img src='link/to/image.png'>");
    ?>

  3. #3
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Default

    Quote Originally Posted by Blinger View Post
    what?

    Wouldn't you just echo the image?
    PHP Code:
    <?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

  4. #4
    Join Date
    Sep 2005
    Posts
    888
    Tokens
    177

    Latest Awards:

    Default

    what is your total source code?

  5. #5
    Join Date
    Nov 2006
    Location
    Liverpool/Manchester
    Posts
    2,457
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by 2fast2kwl View Post
    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
    Last edited by iJoe; 02-06-2010 at 07:30 PM.
    Joe


  6. #6
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Default

    Ijoe, thanks but no luck +rep

    Index.php
    Code:
    <?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

    Code:
    <?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>
    Last edited by Jack!; 02-06-2010 at 07:30 PM.

  7. #7
    Join Date
    Nov 2006
    Location
    Liverpool/Manchester
    Posts
    2,457
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by 2fast2kwl View Post
    Ijoe, thanks but no luck +rep

    Index.php
    Code:
    <?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

    Code:
    <?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}
    Joe


  8. #8
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Default

    Quote Originally Posted by iJoe View Post
    Try putting { } brackets around the
    $pageContent and $pageTitle

    So it'll be {$pageContent} and {$pageTitle}
    why? the code works fine??

  9. #9
    Join Date
    Sep 2005
    Posts
    888
    Tokens
    177

    Latest Awards:

    Default

    where are you trying to include the image?

  10. #10
    Join Date
    Nov 2006
    Location
    Liverpool/Manchester
    Posts
    2,457
    Tokens
    0

    Latest Awards:

    Default

    Oh sorry I thought you were having problems with them pages, ignore that then

    Paste the code you currently have on pj.php
    Joe


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •