PHP PDO Insert gives Parse Error: expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'', help? [closed]
I'm very simply inserting a record into a database using PDO, but I get a parse error
expecting
T_STRING' or
T_VARIABLE' or'{'' or
'$''
which I don't understand. Here's my code:
<?php
$host = "localhost";
$user = "refrigerator";
$pass = "xxxxx";
$dbname = "lifelapse";
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$data = array( 'username' => $username, 'password' => $password, 'email' => $email );
$STH = $DBH->("INSERT INTO users (username, password, email) values (:username, :password, :email)");
$STH->execute($data);
header("Location: confirmation.html");
?>
开发者_JAVA技巧The error is in the line
$STH = $DBH->("INSERT INTO users (username, password, email) values (:username, :password, :email)");
Can anyone shed some light onto this?
Thanks in advance
You need to supply a function.
ie:
$DBH->("INSERT
To
$DBH->prepare("INSERT
I think that you are not calling a method on that line. It should be:
$STH = $DBH->prepare("INSERT INTO users (username, password, email) values (:username, :password, :email)");
You need to call PDO::prepare
-- you're not actually calling a function.
$STH = $DBH->prepare("INSERT INTO users (username, password, email) values (:username, :password, :email)");
精彩评论