Sergey M. Sergey M. - 7 months ago 7
SQL Question

Inserting MySQL data as an image path

When I try to do simple code like this everything works fine:

<?php
require 'connect.php';

if($result = $con->query("SELECT * FROM table")) {
if($row = $result->fetch_object()) {
echo $row->imgName, ' ',$row->divId, '<br>';
}
}
?>


But inserting an image is not working for some reason:

<?php
require 'connect.php';

if($result = $con->query("SELECT * FROM table")) {
if($row = $result->fetch_object()) {
echo "<img src='img/".$row['imgName']."' />";
}
}
?>


Can you help me out, please!

Answer

Change $row['imgName'] to $row->imgName

Comments