I started over with a project I was working on earlier. With the help of my PHP book and a few people on Stack Overflow, I was able to get rid of a lot of the errors I was getting.
Now, I am left with a warning and a fatal error. I understand both errors, I am just not sure how to fix the errors I am getting. Could anyone please help? I am not asking for anyone to write the code or just do everything for me, I just need a point in the right direction.
This is the warning, and it sounds like I need to put __construct somewhere in the uploadFile() method, but again, not sure about this:
Warning: PDO::prepare() [pdo.prepare]: SQLSTATE[00000]: No error: PDO constructor was not called in C:\xampp\htdocs\files\upload.php on line 23
The second, I am just completely lost on what to do about. I realize what the error is telling me, I just don't know where to start in terms of fixing it. Here it is:
Fatal error: Call to undefined method upload::bindParam() in C:\xampp\htdocs\files\upload.php on line 24
If there's anymore information I could provide that would make this easier to answer, please tell me and I will try to get it for you. I appreciate any help!
upload.php
<?php
error_reporting(E_ALL);
require('config.php');
class upload extends PDO
{
public $conURL, $filename, $tmpname, $filesize, $filetype, $file;
public function __construct($config) {
$conURL = "mysql:host=" . $config['host'] . ";dbname=" . $config['db'];
parent::__construct($conURL, $config['user'], $config['pass']);
}
public function uploadFile() {
if ($_FILES['file']['size'] >= 2000000) {
echo "File is too large!";
}
else {
$sth = $this->prepare("INSERT INTO uploads (name, type, size, file) VALUES (?, ?, ?, ?)");
$sth->bindParam(1, $filename);
$sth->bindParam(2, $filetype);
$sth->bindParam(3, $filesize);
$sth->bindParam(4, $file);
$sth->execute();
}
}
}
$upload = new upload($config);
$upload->filename = $_FILES['file']['name'];
$upload->tmpname = $_FILES['file']['tmp_name'];
$upload->filesize = $_FILES['file']['size'];
$upload->filetype = $_FILES['file']['type'];
$upload->file = $_FILES['file'];
$upload->uploadFile();
config.php
<?php
$config = array(
'host' => 'localhost', // db host
'user' => 'root', // db user
'pass' => '', //db pass
'db' => 'files' // db name
);
Edit: Thanks to everyone here, only one error remains and it is the following:
Fatal error: Call to undefined method stdClass::uploadFile() in C:\xampp\htdocs\files\upload.php on line 43
Edit 2: All errors have been resolved, but nothing is being inserted into the database.