0

I got this error and I can't solve it

Call to a member function bindParam() on a non-object in (7 line)

line - $statement->bindParam(':vardas', $_POST['vardas']);

The whole script

<?php
require 'db.php';
if(!empty($_POST['vardas']) && !empty($_POST['slaptazodis']) && !empty($_POST['email'])) {
  $sql = "INSERT INTO nariai (vardas, email, slaptazodis) VALUES(:vardas, :email, :slaptazodis)";
    $statement = $con->prepare($sql);
    
    $statement->bindParam(':vardas', $_POST['vardas']);
    $password_hash = password_hash($_POST['slaptazodis'], PASSWORD_BCRYPT);
    $statement->bindParam(':slaptazodis', $password_hash);
    $statement->bindParam(':email', $_POST['email']);

    if($statement->execute()) {
        $message = 'Account successfully created';
    } else {
        $message = 'Sorry, there must have been an issue creating your account. Try again later';
    }
}
?>
Marco Scabbiolo
  • 7,203
  • 3
  • 38
  • 46
Jus Tas
  • 9
  • 1
  • 1
    Possibilities: your database connection failed, your table name is incorrect, or one of your column names is incorrect. – Patrick Q Jul 11 '16 at 20:21
  • your prepare failed, you failed to check for failure, and since you didn't check for failure, caused further failures. – Marc B Jul 11 '16 at 20:30
  • 1
    Possible duplicate of [Fatal error: Call to a member function bindParam()](http://stackoverflow.com/questions/7941089/fatal-error-call-to-a-member-function-bindparam) – Patrick Q Jul 11 '16 at 20:31

0 Answers0