Why is this PHP PDO snippet not working?
Why is this PHP PDO snippet not working?
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$STH->bindParam(':fftb', $fftb);
$STH->bindParam(':st', $st);
$STH->bindParam(':la', $la);
$STH->bindParam(':cf', $cf);
$STH->bindParam(':total', $total);
$STH = $DBH->prepare("INSERT INTO orders (fftb, st, la, cf, total) VALUES (:fftb, :st, :la, :cf, :total)");
$STH->execute();
+3
undefined
source
to share
2 answers
Because you are trying to execute the parameters bind
in the statement before creating the statement. First prepare()
, then bind
.
+14
deceze
source
to share
Check out the corrected code below:
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$STH = $DBH->prepare("INSERT INTO orders (fftb, st, la, cf, total) VALUES (:fftb, :st, :la, :cf, :total)");
$STH->bindParam(':fftb', $fftb);
$STH->bindParam(':st', $st);
$STH->bindParam(':la', $la);
$STH->bindParam(':cf', $cf);
$STH->bindParam(':total', $total);
$STH->execute();
0
Diwakar kumar
source
to share