Reputation: 23
When it comes to displaying the 48 B Image file would not show.
[code1] This is the code that I am using to insert the image from the back-end.
if(isset($_POST['submit'])){
$pid = mysql_real_escape_string($_POST['productID']);
$productName = mysql_real_escape_string($_POST['productName']);
$productImg = mysql_real_escape_string($_POST['productImg']);
$insert = mysql_query("INSERT INTO products (productID, productName, productImg) VALUES ('$pid', '$productName', '$productImg')");
if($insert)
{
echo 'Successfully added new record.';
} else {
echo 'Failed to add new record because '.mysql_error();
}
} ?>
[code2] and this is the code that I am using to display the image from the front-end.
while($row = mysql_fetch_array($query)){
echo '<tr>
<td>'.$row['productID'].'</td>
<td>'.$row['productName'].'</td>
<td>'.
'<img src="data:image/jpg;base64,'.base64_encode($row['productImg']).'" width="auto" height="150" class="img-thumnail"/>'
.'</td>
Upvotes: 1
Views: 44
Reputation: 327
if you are using <input type="file" />
and if you are not aware this that "you cannot send file type like normal string" check that what you are doing before submit.
Refer this link it may help you:
https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/
Upvotes: 1