First I make the db...
CREATE TABLE `contents`.`tbl_uploads` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`file` VARCHAR( 100 ) NOT NULL ,
`type` VARCHAR( 10 ) NOT NULL ,
`size` INT NOT NULL
) ENGINE = MYISAM ;
I connect to the db using PDO...
try {
$conn = new PDO("mysql:host=$servername;dbname=content", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
Then when the POST request is made I attempt the following...
if(isset($_POST['submit']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
move_uploaded_file($file_loc,$folder.$file);
$sql="INSERT INTO tbl_uploads(file,type,size) VALUES(?,?,?)";
$statement = $conn->prepare($sql);
$statement->execute(array('$file','$file_type','$file_size'));
}
The only thing that seems to work properly is the move_uploaded_file
because the txt file appears in my uploads
folder. However an entry is made in my db but the entry looks like this...
id 1 file $file type $file_type size 0
Why aren't I able to make a proper entry?