i am trying to upload images to a database from an html form.
This script is not connecting to the database and i do not know why.
when i hit submit i get:
This file has the following Database ID: 0
it acts like something happened but no information is goinig to the database.
am i missing a binding or something?
any help would be appreciated.
database is "uptest"
id, int (4), Not Null, Auto_increment primary Key
description, varchar (50), not null
bin_data, longblob, not null
filename, varchar (50) not null
filetype, varchar (50) not null
filesize, varchar (50) not null
"database connection url"
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname = "host";
$database = "database";
$username = "root";
$password = "password";
$firetiki = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
?>
upload script
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Store binary data into SQL Database</title>
</head>
<body>
<?php
if ((isset($_POST['submit']))&&(isset($_FILES['form_data']))) {
upload();
} else {
show_form();
}//end if
function upload()
{//includes
require("database connection url");
//define *variables
$image_file = '';
$image_desc = '';
$type = '';
$size = 0;
$name = '';
$image_file = $_FILES['form_data']['tmp_name'];
$image_desc = $_POST['form_description'];
$type = $_FILES['form_data']['type'];
$size = $_FILES['form_data']['size'];
$name = $_FILES['form_data']['name'];
$data = fread(fopen($image_file, "r"), filesize($image_file));
$data = addslashes($data);
$result = connect("INSERT INTO uptest (description,bin_data,filename,filesize,filetype)"."VALUES ('$image_desc','$data','$name','$size','$type')");
$id = mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
show_form();
}
function show_form()
{
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" 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" size="40">
<p><input type="submit" name="submit" value="submit">
<input type="button" name="move" value="Show" onClick="javascript:window.location='show_desc.php';">
</form>
<?php
}
?>
</body>
</html>