I'm working on a small custom CMS for a browser-based game I'm writing mostly as a learning project and am having trouble writing information to my database. I generally know how this works and have it functioning elsewhere on the project, but here specifically it is giving me some trouble. I know that the POSTs and the $data array in general are working properly because I can echo the information from them just fine. But when I try to write to the database using PDO, nothing seems to make it through.
Here is what I have. I also know that my constants are correct, because I had some information in the database, and it was dropped properly according to my resetDatabase function.
To be clear, it is the processUser function that isn't getting the desired information to the database:
function resetDatabase() {
$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
$sql = 'DROP TABLE IF EXISTS user;
CREATE TABLE IF NOT EXISTS user (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(90) UNIQUE,
username VARCHAR(20),
firstname VARCHAR(40),
lastname VARCHAR(40),
birthday DATE,
password CHAR(128),
registerdate TIMESTAMP
)';
$st = $conn->prepare($sql);
$st->execute();
$conn = null;
}
resetDatabase();
$data = array(
'firstName' => htmlspecialchars($_POST['firstName']),
'lastName' => htmlspecialchars($_POST['lastName']),
'username' => htmlspecialchars($_POST['username']),
'email' => $_POST['email'],
'birthday' => strtotime($_POST['birthday']),
'registerDate' => strtotime('now'),
'password' => hash('sha512', $_POST['password'])
);
function processUser($data = array()) {
$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
$sql = 'INSERT INTO user (email, username, firstname, lastname, birthday,
registerdate, password) VALUES (:email, :username, :firstName,
:lastName, :birthday, :registerDate, :password)';
$st = $conn->prepare($sql);
$st->bindValue(':email', $data['email'], PDO::PARAM_STR);
$st->bindValue(':username', $data['username'], PDO::PARAM_STR);
$st->bindValue(':firstName', $data['firstName'], PDO::PARAM_STR);
$st->bindValue(':lastName', $data['lastName'], PDO::PARAM_STR);
$st->bindValue(':birthday', $data['birthday'], PDO::PARAM_INT);
$st->bindValue(':registerDate', $data['registerDate'], PDO::PARAM_INT);
$st->bindValue(':password', $data['password'], PDO::PARAM_STR);
$st->execute();
$conn = null;
}
processUser($data);
Anyone know where my code is tripping up? Thank you for the help.