They're not working because your binded values contain quotes; remove them.
userLogin=':login'
as
userLogin=:login
"Verifying if a username is not taken worked when I used it like this"
WHERE userLogin='$usernameLC'
- You need to remove the quotes in the bind as already stated on top, and make sure you're using PDO to connect with, as stated below; if that is the case.
Using setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
would have signaled the syntax errors.
Read up on how to use prepared statements in PDO, to prepare and execute:
An insight:
Make sure you are indeed using a PDO connection rather than a mysqli
-based (it's unknown). I see these types of questions often, where OP's use mysqli_
to connect with and querying with PDO.
Those different MySQL APIs do not intermix with each other.
If you're using mysqli_
to connect with:
Add error reporting to the top of your file(s) which will help find errors, if any in regards to your POST arrays, or other possible errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
Edit:
"Thanks, it works great. When logging in though, comparing submitted password to the password in DB returns false. I try stocking the received password in $_SESSION['test'] to see what it gets and print_r($_SESSION); returns me this : Array ( [test] => Array ( [userPwd] => test12 [0] => test12 ) ) (test12 is my password, userPwd is the password Field in the db) Any idea ? ^^"
In regards to a comment you left about using passwords.
It seems you are storing passwords in plain text, rather than a hash. This is highly discouraged, as well as being stored in sessions; a very bad idea.
See this Q&A on Stack on hashed passwords:
Using PHP's password_hash()
function and password_verify()
function.
For PHP < 5.5 use the password_hash() compatibility pack
.
A note about the column type and length when storing a hashed password.
- The password column should be
VARCHAR
.
- It should also be long enough to store the hash.
- Using
VARCHAR(255)
is best.