PHP Code:
<HTML>
<HEAD><TITLE>Update binary data in MySQL 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)));
$updatesql = "
UPDATE binary_data SET
description='$form_description',
bin_data='$data',
filename='$form_data_name',
filesize='$form_data_size',
filetype='$form_data_type'
WHERE id='$id'
";
$result = mysql_query ($updatesql);
print "<p>This file has the following Database ID: <b>$id</b>";
mysql_close ();
} else {
// else show the form with the data that needs to be updated.
$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'
"; // id is passed from previous page
$Result = mysql_db_query ($DBName, $Query, $Link);
while ($Row = mysql_fetch_array($Result)){
print ("<form method=post action=store2.php enctype=multipart/form-data>" );
print ("<input type=text name=form_description value=$Row[description]>" );
print ("<INPUT TYPE=hidden name=MAX_FILE_SIZE value=1000000>" );
print ("<br>File to upload/store in database:<br>" );
print ("<input type=file name=form_data>" );
print ("<p><input type=submit name=submit value=submit>" );
print ("</form>" );
}
mysql_close($link);
}
?>
</BODY>
</HTML>
That's your code looking a bit better. The key point though is ... you say that // id is passed from previous page, but where in your code are you getting the ID value? I don't see it in the form or in a link.
Final point - bad idea to assume the register_globals is On.
Bookmarks