Hello all.
Just been adding a few modifications to the script found @: http://www.phpbuilder.com/columns/florian19991014.php3.
I am trying to add an update script so that entries can be altered / ammended. I've discovered that updating blob data isn't as easy as I thought!
Here's my script so far:
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
if ($submit) {
MYSQL_CONNECT("localhost","matt","r1ffraff");
mysql_select_db("test_matt");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("UPDATE binary_data SET(description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type') WHERE id='$id'");
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<?php
$Hostname = "localhost";
$User = "matt";
$Password = "r1ffraff";
$DBName = "test_matt";
$TableName = "binary_data";
$Link = mysql_connect($Hostname, $User, $Password);
$Query = "Select * from $TableName WHERE id = '$id'";
$Result = mysql_db_query ($DBName, $Query, $Link);
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40" value="<?php echo ($description); ?>">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</BODY>
</HTML>
I know the code is a bit messy at the moment (and obviously broken somewhere), but can anyone point out where I'm going wrong?
Any help would be greatly appreciated.
Thanks
Matt