Hello!
I am having trouble with inserting fields from an HTML form to a MySQL database. Briefly, the objective is to allow a user to upload files to a temporary directory on my server, and then insert the details of the file, as well as the file itself (field BLO😎 to a mysql database called Resource, table name: resource_details.
Below are snippets of my code. An echo message is returned to verify the database has been connected, and also an extra row is added, only to have the ID field there (by auto icrement) All the rest of the fields remain empty.
My code is as follows
<HTML>
<HEAD><TITLE>INSERT Data via PHP</TITLE></HEAD><BODY>
<?PHP
$connection=mysql_connect("localhost","root","") or die('Could not connect to the database server');
$db = mysql_select_db("Resource", $connection) or die ("Unable to select database.");
$userfile_name = $FILES['fileupload']['name'][0];
$userfile_tmp = $FILES['fileupload']['tmp_name'][0];
$filedir = "c:\program files\apache group\apache2\htdocs\Up_files\";
$location = "$filedir/$userfile_tmp";
$fileHandle = fopen($location, "rb");
$fileContent = fread ($fileHandle, $fileupload_size);
$fileContent = addslashes($fileContent);
$sql = "INSERT INTO resource_details VALUES ('$resource_id', '$name', '$file_type', '$title', '$language', '$author', '$keyword_1', '$keyword_2', '$keyword_3', '$original_date', '$fileContent')";
$sql_result = mysql_query($sql,$connection) or die ('Could not insert data');
echo('Data inserted successfully.');
mysql_close($connection);
?>
</form>
</BODY>
</HTML>
Any help would be much appreciated.
Cheers