I am trying to create a duplicate username checker and I am thinking this is probably the way to do it correct me if im wrong. Basically I want the username the user input to be stored in a variable called userName
and then use that variable to check and see if there are any LIKE
rows in the database and if so return a count of 1 or more to a variable named $count
I would then have an IF ELSE
statement that would either yell at the user or let them continue. I have run into a problem using the LIKE
statement. I think my syntax could be wrong since I have been trying several different methods but still no luck.
Main Code
<?php
require 'DB.php';
$userName = "tes";
echo $userName;
try{
$stmt = $conn->prepare('SELECT COUNT(*) FROM `CLL_users` WHERE `user_name` LIKE "% . ":userName" . "');
$stmt->bindValue(':userName', $userName);
$stmt->execute();
$count = $stmt->fetchColumn();
return $count;
echo $count;
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
?>