PHP PDO Username Availability Checker
Posted
by
John Bernal
on Stack Overflow
See other posts from Stack Overflow
or by John Bernal
Published on 2012-09-29T21:28:35Z
Indexed on
2012/09/29
21:37 UTC
Read the original article
Hit count: 171
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
© Stack Overflow or respective owner