Hi all,
I am new to this group and PHP programming.
I have a very simple question.
I have a database where I want to store and display all images.
I have inserted few images in the database and now I want to display all of them.
I get only one image display and not all.
If I try to change the code line in for-loop
echo $bytes[$x]."
";
with
echo '
';
no image is displayed.
*********************************************
file name: insert_complete.php
<?php
$productName=$_POST[productName];
$productPrice=$_POST[productPrice];
//$imagefile=$_POST[imagefile];
$imagefile=$_POST[imagefile];
$whatsit=$_POST[whatsit];
// Connect to database
$errmsg = "";
if (! @mysql_connect("localhost","root","")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("dummy");
if ($_REQUEST[completed] == 1) {
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")))
if (strlen($instr) < 149000) {
echo "Inside Inser";
$sql = "INSERT INTO pix ";
$sql .= "(productName, producPrice, title, imgdata) ";
$sql .= "VALUES ('$productName', '$productPrice', '$whatsit','$image')";
mysql_query($sql);
} else {
$errmsg = "Too large!";
}
while ($row = @mysql_fetch_assoc($gotten)) {
$pName = htmlspecialchars($row[productName]);
$pPrice = htmlspecialchars($row[producPrice]);
$title = htmlspecialchars($row[title]);
$bytes[] = $row[imgdata];
}
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
for ($x=0; $x < count($bytes); $x++){
echo $bytes[$x]."
";
//echo '
';
}
exit ();
}
<html><head>
<title>Insert Complete</title>
<body bgcolor=white><h2>Here's the latest picture</h2>
<?= $errmsg ?>
<center><?php require 'insert_complete.php?gim=1'; ?>
<?= $title ?></center>
<hr>
<h2>Upload a new product to Database.</h2>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=150000>
<input type=hidden name=completed value=1>
Product Name: <input type="text" name="productName">
Product Price: <input type="text" name="productPrice">
Please choose an image to upload: <input type=file name=imagefile>
Please enter the title of that picture: <input name=whatsit>
then: <input type=submit></form>
</body>
</html>