PHP PDO Username Availability Checker
- by John Bernal
I'm building a registration page that uses JQuery's validator plugin to validate the form. For the username, i used the remote method. So here's my jquery+html code: fiddle
And here's Available.php:
<?php
$usr = $_POST["username"];
$link = new PDO('mysql:***;dbname=***;charset=UTF-8','***','***');
$usr_check = $link->prepare("SELECT * FROM Conference WHERE Username = :usr");
$link->bindParam(':usr', $usr);
$usr_check->execute();
if($usr_check->rowCount()>0)
echo "false";
else
echo "true";
?>
So I have a test account in my database with the username: user. When I tried to submit my form with the same username, it didn't display the error saying "username taken" which means the php isn't correct. Any ideas where I went wrong? Thanks