Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP in HTML

Posted on 2009-07-01
8
Medium Priority
?
319 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 400 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 1200 total points
ID: 24756142
Verify you have value in this variable, $FlagImage
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 1200 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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…
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 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…
Suggested Courses

824 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