PHP Session Variable and MySQL INSERT INTO Trouble
Posted: Wed Dec 15, 2010 5:29 pm
I have a photo upload script that I am working on and I have never run into this problem before. Everything on the script works fine, however on the insert into command the business_id session variable is not being posted to the database. It is showing up as empty. I do not know what I am doing wrong and as far as I see it should work. Any help would be appreciated.
Code: Select all
<?php
session_start();
include('../includes/database.php');
function genRandomString() {
$length = 128;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*';
$string = ”;
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$random = genRandomString();
$randommd5 = md5($random);
$path_parts = pathinfo($_FILES['uploadfile']['name']);
$extension = $path_parts['extension'];
$newfile = $randommd5 . "." . $extension;
if($_FILES['uploadfile']['size'] > 1048576){
echo "error file size > 1 MB";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
if($_FILES['uploadfile']['error'] >= 1){
echo "unknown error";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
if(move_uploaded_file($_FILES['uploadfile']['tmp_name'], "../uploads/$newfile")){
mysql_query("INSERT INTO account_pictures (business_id, picture) VALUES ('{$_SESSION['business_id']}','$newfile')");
echo "success";
}
?>