Use img source with php variable?
I have the following code in my detailansicht.php:
<div class="file_description_box">
<b>Beschreibung:</b><br /><br />
<?php
if(!empty($beschreibung))
echo '<div align="center">';
echo '<img src="$coverlink" alt="Cover">';
echo '</div><br />';
echo format_content($beschreibung);
**else**
echo '<i>Keine Beschreibung vorhanden</i>';
?>
</div>
but I think there should be an error in the img tag. every time I open the page, it shows me an error: "Syntax error: syntax error, unexpected T_ELSE in bla / bla / include / detailansicht.php on line 123" (line 123 is the highlight in bold). I tried several methods, but always get this error. It would be nice if someone helped me with this.
-sTarbuZz
+3
sTarBuZz
source
share8 answers
You are missing curly braces and your PHP variable was not inline. Your code should look like this:
<div class="file_description_box">
<b>Beschreibung:</b><br /><br />
<?php
if(!empty($beschreibung)){
echo '<div align="center">';
echo '<img src="'.$coverlink.'" alt="Cover">';
echo '</div><br />';
echo format_content($beschreibung);
}else{
echo '<i>Keine Beschreibung vorhanden</i>';
}
?>
</div>
, , PHP, , , , , HTML, , .
PHP, , .
+15