I am trying to get an image that is saved as a URL in a MySQL database to display on a webpage as an image rather than a URL. With the code below it displays as a URL:
<?php
// Connects to your Database
mysql_connect("server","username","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$id=$_GET["id"]; // Collecting data from query string
if(!is_numeric($id)){ // Checking data it is a number or not
echo "Data Error";
exit;
}
$data=mysql_query("SELECT * FROM `table_name` WHERE `User_ID`=$id");
$row=mysql_fetch_object($data);
echo mysql_error();
echo"<tr><td colspan='2'>$row->Market_Name</td></tr>";
echo"<tr><td colspan='2'>$row->Days</td></tr>";
echo"<tr><td colspan='2'>$row->Time</td></tr>";
echo"<tr><td colspan='2'>$row->Description</td></tr>";
echo"<tr><td>$row->Image</td><td>$row->Google_Maps</td></tr>";
echo"<tr><td>$row->Website</td><td>$row->Facebook</td></tr>";
?>
If I change this piece of code:
echo"<tr><td>$row->Image</td>
to:
echo"<tr><td><img src='Image/".$row['Image']."' width='150' height='80'>
I get the following error:
PHP Fatal error: Cannot use object of type stdClass as array
Is there a way using object rather than array to display an image that is saved as a URL in a MySQL database?
$row['Image']to work you'd have had to usemysql_fetch_arrayormysql_fetch_associnstead ofmysql_fetch_object.