I can't upload picture to MySQL database:
What is wrong with my script:
I use PHP & MySQL database.
After submiting form my script says that everything is OK, but in database I
see that a picture is not uploaded.(date, size, name, type are inputed, but
data is not!).

Table:

CREATE TABLE pictures (
picture_id int(11) DEFAULT '0' NOT NULL,
name varchar(30) NOT NULL,
date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
pic_data mediumblob NOT NULL,
pic_size int(11) DEFAULT '0' NOT NULL,
pic_type varchar(30) NOT NULL,
PRIMARY KEY (picture_id)
);



My PHP page:


<?php
include_once("db_mysql.php");
class pictures_db extends DB_Sql
{
var $Host="localhost";
var $Database="sajt";
var $User="root";
var $Password="";
}
$aErrors=False;
if (!empty($PicFile_name))
{
if ( ($PicFile_type == "image/gif") ||
($PicFile_type == "image/pjpeg") ||
($PicFile_type == "image/jpeg"))
{
$aFile=fopen($PicFile, "rb");
$aFileContents=addslashes(fread($aFile, filesize($PicFile)));
fclose($aFile);
$aDB=new pictures_db();
$aSQL="select(max(picture_id) + 1) as new_id from pictures";
$aDB->query($aSQL);
if ($aDB->next_record() )
{
$aNewID=$aDB->f("new_id");
}
if(empty($aNewID) == True)
{
$aNewID=1;
}
$aSQL="insert into pictures (picture_id, name, ".
"date, pic_data, ";
$aSQL .="pic_size, pic_type) values ($aNewID, ".
"'$PicName', ";
$aSQL .= "NOW(), '$aFileContents', '$PicFile_size', ".
"'$PicFile_type' )";
print($aSQL);
$aDB->query($aSQL);
if ($aDB->Errno != 0)
{
$aErrors = True;
}
}
else
{
$aErrors= True;
}
}
else
{
$aErrors = True;
}
if ($aErrors == False)
{
print("OK");
}
else
{
print("ERROR!!!");
}
?>


 ---------------------
 ---------------------
     Šurovski Dejan
   [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to