1

I am getting an error on the $db line. I have tried placing a '->" before the prepare but then I get a Parse Error Syntax Error.

//try to login  
$db = pdo-prepare($sql);  
$username = $db->bindValue($_POST['username']);  
$password = $db->bindValue($_POST['password']);  
$tablePrefix = "";  
$UserAndPassTable = $tablePrefix . "user";
1
  • You need to set your PDO connection into $db before you can call prepare() . Then it would be $db->prepare($sql) I think this post gives real good information on how to use PDO prepared statements. stackoverflow.com/a/767520/6208463 Apr 23, 2017 at 1:59

1 Answer 1

2

You need to set your PDO connection into $db before call prepare()

$stmt=$db->prepare($sql);

In my example $db is my PDO connection

$db = new PDO('mysql:host=localhost;dbname;charset=utf8', 'user', 'pass');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.