I have created an data base in my sql and decided to add some picture but the problem is that the picture that should be loaded currently returns an empty string. So where the correct image should appear on the website is just an image icon
Here you can see what the current website looks like and where the image icons are.
CREATE TABLE IF NOT EXISTS permissions(
typ int NOT NULL,
dvd_hinzufügen BIT NOT NULL,
dvd_löschen BIT NOT NULL,
dvd_bearbeiten BIT NOT NULL,
dvd_ausgeben BIT NOT NULL,
kunden_anlegen BIT NOT NULL,
kunden_bearbeiten BIT NOT NULL,
FOREIGN KEY (typ) REFERENCES benutzer(typ)
);
I have filled this table with some data. Here you can only see some of the movies I added
INSERT INTO dvd (titel, genre, fsk, laenge, darsteller, regisseur, anzahl, bild) VALUES
('Pulp Fiction', 'Krimi', 16, 154, 'John Travolta', 'Quentin Tarantino', 5,
LOAD_FILE('/Bilder/pulp_fiction.jpg')),
('The Shawshank Redemption', 'Drama', 12, 142, 'Tim Robbins', 'Frank Darabont', 5,
LOAD_FILE('/Bilder/the_shawshank_redemption.jpg')),
('The Godfather', 'Krimi', 16, 175, 'Marlon Brando', 'Francis Ford Coppola', 5,
LOAD_FILE('/Bilder/the_godfather.jpg')),
('Fight Club', 'Drama', 18, 139, 'Brad Pitt', 'David Fincher', 5,
LOAD_FILE('/Bilder/fight_club.webp')),
('Forrest Gump', 'Drama', 6, 142, 'Tom Hanks', 'Robert Zemeckis', 5,
LOAD_FILE('/Bilder/forrest_gump.jpg')),
('Inception', 'Sci-Fi', 12, 148, 'Leonardo DiCaprio', 'Christopher Nolan', 5,
LOAD_FILE('/Bilder/inception.png'));
The path to the images should be correct. My databank.sql file is in the same ordner as the ordner bilder which contains the images.
Then I requested the images in my php part.
if (!isset($_GET['search']) || ($_GET['search'] == '')) {
//abfrage aller Filme aus Datenbank
$sql = "SELECT titel, bild FROM dvd ORDER BY $selectedCategory $selectedSort" ;
$res = $con->query($sql);
if ($res->num_rows > 0){
while($i = $res->fetch_assoc()){
$bild = base64_encode($i['bild']);
echo "<p>" .$i["titel"]."</p>";
echo '<img src="data:image/jpeg;base64,'.$bild.'" />';
}
}
}
else if (isset($_GET['search'])) {
//abfrage Filme aus Datenbank
$searchTerm = $con->real_escape_string($_GET['search']);
$sql = "SELECT titel, bild FROM dvd WHERE titel LIKE '%$searchTerm%' or genre LIKE '%$searchTerm%' or fsk LIKE '%$searchTerm%' or darsteller LIKE '%$searchTerm%' or regisseur LIKE '%$searchTerm%' ORDER BY $selectedCategory $selectedSort" ;
$res = $con->query($sql);
if ($res->num_rows > 0){
while($i = $res->fetch_assoc()){
$bild = base64_encode($i['bild']);
echo "<p>" .$i["titel"]."</p>";
echo '<img src="data:image/jpeg;base64,'.$bild.'" />';
}
}
}
I tried with echo "<p>Length: " . strlen($bild) . "</p>";
to see if the length of the varaible $bild is 0, which actully is. I also right clicked the image icons and opend them in the editor where I could see <p>A Beautiful Mind</p><img src="data:image/jpeg;base64," /><p>Eternal Sunshine of the Spotless Mind</p><img src="data:image/jpeg;base64," /><p>Gladiator</p><img src="data:image/jpeg;base64," /><p>Jurassic Park</p><img src="data:image/jpeg;base64," /><p>Toy Story</p><img src="data:image/jpeg;base64," /> </div>
.
In conclusion the problem should be that the images arent loaded properly with the load file function which makes no sense. I hope I could provide enough sample. Otherwise comment this and I will provide more.