got two simple php files for inserting and showing a jpeg from an sql db
Insert code
<?php
$conn = mysqli_connect("localhost", "root", "admin", "test");
$conn->query("CREATE TABLE files (id INTEGER PRIMARY KEY AUTO_INCREMENT, "."data BLOB)");
$stmt = $conn->prepare("INSERT INTO files VALUES(NULL, ?)");
$stmt->bind_param("s", $data);
$file = "test.jpg";
$fp = fopen($file, "r");
$size = 0;
while ($data = fread($fp, 1024)) {
$size += strlen($data);
$stmt->send_long_data(0, $data);
}
//$data = file_get_contents("test.jpg");
if ($stmt->execute()) {
print "<p>$file ($size bytes) was added to the files table</p>";
print "<a href=\"getit.php\">Click here to view<a>";
} else {
die($conn->error);
}
?>
read code
<?php
$conn = mysqli_connect("localhost", "root", "admin", "test");
$result = $conn->query("SELECT data FROM files");
while($row = $result->fetch_row()){
print "$row[0]\n";
}
?>
what i want to know is why it only ever displays one jpeg when i Know ive inserted two or more.
thanks in advance
john
ps im new to php so go easy.