Hi all,
When running the following i get this error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null
and heres the code:
function upload(){
/*** check if a file was uploaded ***/
if(is_uploaded_file($_FILES['userfile']['tmp_name']) && getimagesize($_FILES['userfile']['tmp_name']) != false)
{
/*** get the image info. ***/
$size = getimagesize($_FILES['userfile']['tmp_name']);
/*** assign our variables ***/
echo $user = $_REQUEST['id'];
echo $owner = $_REQUEST['p'];
$type = $size['mime'];
$imgfp = fopen($_FILES['userfile']['tmp_name'], 'rb');
$size = $size[3];
echo $name = $_FILES['userfile']['name'];
echo $maxsize = 99999999;
/*** check the file is less than the maximum file size ***/
if($_FILES['userfile']['size'] < $maxsize )
{
/*** connect to db ***/
$dbh = new PDO("mysql:host=localhost;dbname=db", 'un', 'pw');
/*** set the error mode ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** our sql query ***/
$stmt = $dbh->prepare("INSERT INTO testblob (user_id, item_id, image_type ,image, image_size, image_name) VALUES (?, ?, ? ,?, ?, ?)");
/*** bind the params ***/
$stmt->bindParam(1, $user);
$stmt->bindParam(2, $owner);
$stmt->bindParam(3, $type);
$stmt->bindParam(4, $imgfp, PDO::PARAM_LOB);
$stmt->bindParam(5, $size);
$stmt->bindParam(6, $name);
/*** execute the query ***/
$stmt->execute();
}
else
{
/*** throw an exception is image is not of type ***/
throw new Exception("File Size Error");
}
}
else
{
// if the file is not less than the maximum allowed, print an error
throw new Exception("Unsupported Image Format!");
}
}