开发者

PHP PDO Insert gives Parse Error: expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'', help? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I'm very simply inserting a record into a database using PDO, but I get a parse error

expecting T_STRING' orT_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)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜