0

I'm trying to log data into my database, but I keep getting the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'firstName' in 'field list'

I have done research and still haven't found the answer. Do I have any unseen mistakes in my code? Am I doing something wrong? I don't see why I'm getting this error, my database does have a column called firstName. Thanks.

$db = new PDO('mysql:host=localhost;dbname=bord','root','root');
  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "INSERT INTO users (firstName, lastName, password, email, code, active, month) VALUES (
    :firstName, :lastName, :password, :email, :code, :active, :month
  )";
  $statement = $db->prepare($sql);
  $statement->bindParam(':firstName', $firstName);
  $statement->bindParam(':lastName', $lastName);
  $statement->bindParam(':password', $password);
  $statement->bindParam(':email', $email);
  $statement->bindParam(':code', $code);
  $statement->bindParam(':active', $active);
  $statement->bindParam(':month', $month);

  $firstName = 'Mitchell';
  $lastName = "Sanders";
  $password = "password";
  $email = "msandy@fakemail.com";
  $code = 12345;
  $active = 0;
  $month = date("F");
  $statement->execute();
Sean Bone
  • 3,368
  • 7
  • 31
  • 47
  • 3
    Obviously it doesn't. Check column names again. Maybe ist' `fistrName` or `firtsName` or whatever. – u_mulder Oct 12 '16 at 20:34
  • 1
    **Never store plain text passwords!** Please use PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html) to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). Make sure you ***[don't escape passwords](http://stackoverflow.com/q/36628418/1011527)*** or use any other cleansing mechanism on them before hashing. Doing so *changes* the password and causes unnecessary additional coding. – Jay Blanchard Oct 12 '16 at 20:36
  • To add to what @u_mulder already stated, make sure the column name does not have any blank spaces in it you may not be noticing, such as `\` firstName\`` – Uueerdo Oct 12 '16 at 20:42
  • 1
    Might as well add the mysql ddl to this question too. – Jon McEroy Oct 12 '16 at 20:50

0 Answers0