In the following code, I am trying to check if the username entered has been used or not by counting the username.
<?php
$hostname = 'aaa';
$username = 'bbb';
$password = 'ccc';
$prefix = "";
$dbna = 'ddd';
$username11 = $_POST['username'];
try {
$dbh = new PDO("mysql:host=$hostname;dbname=$dbna", $username, $password);
$nRows = $pdo->query("SELECT count(Username) FROM Users WHERE Username ='$username11'")->fetchColumn();
if($nRows)
{
echo '<span style="color: red;">The username <b>'.$username11.'</b> is already in use. </span>';
}
else
{
echo 'OK';
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
The error is:
Fatal error: Call to a member function query() on a non-object in /home/check.php on line 10
I looked for the solution for this error but I couldn't find it.