I am learning the most basic of PHP MYSQL and am trying to display and image on my page along with Name, etc. In the database I made a path: images/Paul.jpg alongside his first name and last name Everything display as expected except for image. I have tried many iterations of the code but it either errors or displays a placeholder with no image or even on inspection doesnt show a path to the image directory.
Any thoughts?
<?php echo $data['first_name']; ?>
<?php echo $data['last_name']; ?>
<?php echo $data['age']; ?>
<?php echo '<img src="['image']" />'; ?>
<?php echo $data['bio']; ?>
<?php
}
?>
<!-- </table> -->
<?php mysqli_close($db); // Close connection ?>
CodePudding user response:
If you have the path in your database, then you should use the path in the src
attribute of your img
<?php echo '<img src="' . $data['image'] . '" />'; ?>
You also need to make sure the directory with your image is at the same level as this file to display correctly or you'll get an incorrect path.