I am trying to create a table that will display the new suggested products by users to allow a moderator to to choose which get approved. For now, all I am trying to do is show the image, as well as the user that submitted it and some other info. I know my problem is with the bottom echo statement that tries to put together a working url by combining the file location and the name of the file itself from the database, which is stored like “Roots.jpg” or like “brock.jpg” Thanks for any help. I am pretty new to php.
<html> <title>Forum Approval</title> <body> <?php $db_host = "host"; $db_username = "user"; $db_pass = "pass"; $db_name = "name"; $pdo = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $sql = "SELECT * FROM add_new_product"; $stmt = $pdo->prepare($sql); $stmt->execute(); ?> <table border='1' align='center'> <caption>Products to approve</caption> <tr> <th>Product Id</th> <th>User Id</th> <th>Name</th> <th>Company</th> <th>Image</th> </tr> <?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo '<tr>'; echo '<td>' . $row['new_prod_ID'] . '</td>'; echo '<td>' . $row['user_ID'] . '</td>'; echo '<td>' . $row['name'] . '</td>'; echo '<td>' . $row['company'] . '</td>'; echo "<td><img src = "a link/uploads/ . $row['image']" . width='100'></td>"; echo '</tr>'; } ?> </table> </body> </html>
Answer
Try changing the echo to something like…
echo "<td><img src="path/to/directory/".$row['image']."" width='100'></td>
The src would be path/to/directory/Roots.jpg