I want to display a thumbnail of a product next to the title and the description. I assume I have to use a blob type and insert it into the page using another php form. My code doesn’t really seem to work, how can I display the image that I uploaded into a product together with the title and description? (Title and description are working)
My database name is “luxsearch” and I use the table “products”
1 id int(11) Auto_Increment
2 image blob
3 title Varchar(64)
4 description Varchar(320)
5 keywords Varchar(120)
6 link Varchar(2011)
Here is my page (It`s Portuguese) :
<?php $conn = mysqli_connect("localhost", "root", "", "luxsearch"); if(mysqli_connect_errno()){ echo "Falha para conectar: " . mysqli_connect_error(); } error_reporting(0); $output = ''; if(isset($_GET['q']) && $_GET['q'] !== ' '){ $imageData = mysqli_real_escape_string(file_get_contents($_FILES["image"] ["tmp_name"])); $searchq = $_GET['q']; $q = mysqli_query($conn, "SELECT * FROM products WHERE keywords LIKE '%$searchq%' OR title LIKE '%$searchq%' OR description LIKE '%$searchq%'") or die(mysqli_error()); $c = mysqli_num_rows($q); if($c == 0){ $output = 'Nenhum resultado encontrado para "' . $searchq . '".
'; } else { while($row = mysqli_fetch_array($q)){ $id = $row['id']; $image = $row['image']; $title = $row['title']; $desc = $row['description']; $link = $row['link']; $output .= '"' . $title . '
' . $desc . '
'; } } } else { header("location: ./"); } print("$output"); mysqli_close($conn); ?>And here is my showimage.php :
<?php mysqli_connect("localhost", "root", "Fishing50", "luxsearch"); if(isset($_GET['id'])){ $id = mysqli_real_escape_string($_GET['id']); $q = mysqli_query("SELECT * FROM 'blob' WHERE 'id'='$id'"); while($row = mysqli_fetch_assoc($q)){ $imageData = $row["image"]; } header("content-type: image/jpeg"); echo $imageData; } else { echo "Erro!"; } ?>