Hey i have a big problem, i have write some php to insert some pics with some other fields in database, all works fine till i am trying update all fields (if i select new image from "browse" all works fine), but if i dont select any image it clear my blob field and i loose the blob image.
Anyone can help me make this work???
my code for update.php is:
<?php
include("../dtb.php");
$sql1 = "SELECT a.* FROM $tbl_prod";
$sql1 = "SELECT * FROM $tbl_cat";
$result1 = mysql_query($sql1);
?>
<html>
<head>
<title>update</title>
</head>
<body>
<?php
if ($id)
if ($submit) {
$data = addslashes(fread(fopen($prod_img, "rb"), filesize($prod_img)));
$sql = "UPDATE $tbl_prod SET
id='$id',
prod_cat='$prod_cat',
prod_name='$prod_name',
prod_desc='$prod_desc',
prod_img='$data',
filename='$prod_img_name',
filesize='$prod_img_size',
filetype='$prod_img_type'
WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.\n";
} else {
// query the DB
$sql = "select * from $tbl_prod";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form method="post" ENCTYPE="multipart/form-data" action="<?php echo $PHP_SELF?>">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Category: <input type="Text" name="prod_n" value="<?php echo $myrow['cat_n'] ?>"><br>
Product name: <input type="Text" name="prod_n" value="<?php echo $myrow["prod_n"] ?>"><br>
Product desc: <input type="Text" name="prod_desc" value="<?php echo $myrow["prod_desc"] ?>"><br>
Change image: <input name="prod_img" type="file">
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
} else {
// display list of products
$result = mysql_query("SELECT * FROM $tbl_prod",$dbh);
while ($myrow = mysql_fetch_array($result)) {
echo $myrow['prod_n'];
echo " | ";
printf("<a href=\"%s?id=%s\">Update</a><br>\n", $PHP_SELF, $myrow["id"]);
}
}
?>
</body>
</html>