Solved

PHP in HTML

Posted on 2009-07-01
8
305 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why do people dis php? 5 49
Insert values are dynamic 11 41
preventing spam with mailto 22 31
Loop through multiple arrays 13 27
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

776 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