Solved

PHP in HTML

Posted on 2009-07-01
8
304 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Animated .jpg? 13 62
Access Object's Property 9 22
phpmailer in WHILE loop - weird results 10 29
I want to echo out my field names with its values into a table 10 12
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now