I am having trouble with URLs stored in my database not displaying properly. Here is my code:
$sqlCommand =
"SELECT rotator.title, rotator.imageURL, rotator.targetURL, rotator.caption FROM rotator
WHERE ( ( rotator.visible = '1' )
OR ( rotator.visible = '2' AND ( NOW() BETWEEN rotator.schedstart AND rotator.schedstop ) ) )
ORDER BY rotator.displayorder ASC";
$query = mysqli_query($myConnection,$sqlCommand) or die (mysqli_error($myConnection));
$rotatorsDisplay = '';
while ($row = mysqli_fetch_array($query)){
$rotatorstitle = $row["title"];
$rotatorsimg = $row["imgURL"];
$rotatorsURL = $row["targetURL"];
$rotatorscaption = $row["caption"];
$rotatorsDisplay .= '<li>
<a href="'. $rotatorsURL .'"><img src="'. $rotatorsimg .'"></a>
<div id="title">'. $rotatorstitle .'</div>
<div class="caption">'. $rotatorscaption .'</div>
</li>';
}
mysqli_free_result($query);
The thing that’s causing me trouble is the $rotatorsimg variable. In the database, I have manually entered values for rotator.imageURL that look like this: ‘images/rotator/name.jpg’ but when I query them from the database, add them to the $rotatorsDisplay variable, then output them with this code:
<?php echo $rotatorsDisplay; ?>
All I get in the resulting page is this:
<a href="doctor.php"><img src=""></a>
I’m pretty sure the reason this isn’t working is the slashes in the URL. I’m also pretty sure I need to somehow encode/convert HTML to strip special characters from code I enter into my database, then decode/convert it back to HTML when I output it, but since I entered this info manually into the database using phpMyAdmin, I haven’t worked out how to do this yet.
Any help is appreciated!
It looks like you’re using the wrong index key.
should probably be
since that’s what you’re querying from the database.