Solved

PHP in HTML

Posted on 2009-07-01
8
301 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

11 Experts available now in Live!

Get 1:1 Help Now