I have been working with this script for a while and everything works great. I know it's a little ruff, but it works. I want to add the project number to the database and I'm going to use sessions to pass the project number.
<?php
session_start();
// code that will be executed if the form has been submitted:
if (isset($_REQUEST['submit'])) {
include 'config.php';
/*** create a new mysqli object with default database***/
$connection = mysqli_connect($hostname, $username, $password, $dbname) or die ("Unable to connect");
$data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), $_FILES['form_data']['size']));
// sql to INSERT a new record
$sql = "INSERT INTO pix (title,imgdata,filename,filesize,filetype,fk_project_id)
VALUES ('$_POST[form_description]', '".$data."','".$_FILES['form_data']['name']."',
'".$_FILES['form_data']['size']."','".$_FILES['form_data']['type']."',
'$_POST[$pid]')";
//excute query
$result = mysqli_query($connection, $sql) or die ("Error in query: $sql. ".mysqli_error());
//$id= mysqli_insert_id();
print "<p>This file has the following Database:<b>$_POST[form_description]</b>";
print "<p>This file has the following project id: <b>$_POST[pid]</b>";
// close connection
mysqli_close($connection);
} else {
// else show the form to submit new data:
?>
<?php
$pid = $_SESSION['pid'];
echo $pid;
?>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<form method="post" action="store.php" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data">
<p><input type="submit" name="submit" value="submit">
<input type="hidden" name="pid" value="<?php echo $pid; ?>">
</form>
<?php
}
?>
</BODY>
</HTML>
Everything works, except the inserting of the project number (pid).
Thanks for any help that you can provide.
A