user1173169
user1173169

Reputation:

"Name must be a string" error in Insert query using PDO

I have a strange error in this block:

   public static function saveUser($form)
{

    $connexion = new PDO("mysql:host=localhost;dbname=cdiscodb", 'root', 'rthr'); // connexion à la BDD
    $connexion->setAttribute  (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO ope_tartine_nl(first_name,last_name,email,created_date,updated_date) VALUES (?,?,?,?,?)";
    $cmd = $connexion->prepare($sql);
    $result = $connexion->exec(array($form['name'], $form['lastname'], $form['email'], date("Y-m-d H:i:s"), date("Y-m-d H:i:s")));
}

the error is :

Fatal error: Function name must be a string

Thanks for your help

Upvotes: 1

Views: 322

Answers (1)

Dev
Dev

Reputation: 186

$sql = "INSERT INTO ope_tartine_nl(first_name,last_name,email,created_date,updated_date) VALUES (?,?,?,?,?)";
$cmd = $connexion->prepare($sql);
$result = $cmd->execute(array($form['name'], $form['lastname'], $form['email'], date("Y-m-d H:i:s"), date("Y-m-d H:i:s")));
}

you have given as $connexion->exec whereas it should be $cmd->exec(......)

And Use $cmd->execute instead of $cmd->exec.

Upvotes: 2

Related Questions