Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP in HTML

Posted on 2009-07-01
8
311 Views
Last Modified: 2012-05-07
I have a line of HTML code which inserts an image placeholder into a table and I have the img src stored in a PHP variable. For some reason I can not get the variable to echo anything. So when I view the page the sorce code shows <img src ="">. What am I doing wrong? (I have echoed the variable out elsewhere on the page and it echo's fine.)
<td> <img src="<? echo $FlagImage ?>" alt="Flag Image" name="FlagPlaceHolder" width="150" height="150" id="FlagPlaceHolder" /> </td>

Open in new window

0
Comment
Question by:dannyg280
8 Comments
 
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 100 total points
ID: 24756088
Try using full PHP tags:
<img src="<?php echo $FlagImage; ?>" alt=...

Open in new window

0
 

Author Comment

by:dannyg280
ID: 24756141
That did not affect it... I have php variable echoed throughout the page.. all others echo correctly. I have tried echoing the same variables that echo correctly on other parts of the page in the <img src...> and I still get nothing... here's a bit more of my code below: All the other vaiables are echoing fine...
<table width="487">
  <tr>
    <td colspan="4"><div align="center" class="style12">
      <p class="style4">Audit Report For Store #<? echo $StoreNum ?></p>
      <p class="style4"><? echo $City ?>, <? echo $State ?>&nbsp;</p>
    </div></td>
    <td> <img src='<?php echo $FlagImage; ?>' alt="Flag Image" name="FlagPlaceHolder" width="150" height="150" id="FlagPlaceHolder" /> </td>

Open in new window

0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 300 total points
ID: 24756142
Verify you have value in this variable, $FlagImage
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 300 total points
ID: 24756153
May be try to echo $FlagImage , out side the img ... and check it
0
 

Author Comment

by:dannyg280
ID: 24756259
I have... when I echo it out I get:  ../HAN/images/RedFlag.png

UPDATE: when I echoed the $City vairable in the <img src > it did appear in the souce code on the webpage..  and as I said, when I echo $ImageFlag elsewhere on the page it echos out fine... I'm at a loss... I've tried changing the variable to just RedFlag.png and typing in the path and just echoing the image name but I get the same result... everything except the echoed value appears :(
0
 

Author Comment

by:dannyg280
ID: 24756552
This seems odd.... I have an external php file that I call VarConversions which I include() in the page. This file pulls my vairables from a database and changes the values for disply on the webpage. I have the code below in the VarConversions.php script...
If I manually define $FlagImage without using "if" staements, then it works fine, but when I use the if statements to define the variable it will not echo in the img src.
(Remember, the $FlagImage varibable DOES echo correctly outside of the img src, so I know the conversion is happening properly)
//Flag Image Coversion
if ($FlagColor =="G") {
$FlagImage = "../HAN/images/GreenFlag.png";
}
else if ($FlagColor =="Y") {
$FlagImage = "../HAN/images/YellowFlag.png";
}
else if ($FlagColor =="R") {
$FlagImage = "../HAN/images/RedFlag.png";
}

Open in new window

0
 
LVL 8

Assisted Solution

by:lharrispv
lharrispv earned 100 total points
ID: 24756707
Try:

<img src=<?php echo "'" + $FlagImage; + "'"?> alt="Flag Image" name="FlagPlaceHolder" width="150" height="150" id="FlagPlaceHolder" />
0
 

Author Comment

by:dannyg280
ID: 24756918
I figured out my problem... and I apoligize for wasting your time (I will be assigning points to all who tried to help). The issue was my fault, the query I run to pull the $FlagColor (and other variables) from the database was actually running after I inserted the $FlagImage varible into the script.. so when I tried to have the image appear at the top of the screen, the variable did not have a value. When I tested it by echoing the varible on another part of the page, I was echoing it out further down, after the query had run.
   Thanks to all who offered help.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question