Reputation: 141
I am trying to get this PHP working where it returns true or false if the username exists in the username column on the database:
$data = array($_POST["username"]);
$db = new PDO('mysql:host=localhost;dbname=Example;charset=utf8', 'Example', 'Example');
$stmt = $db->prepare("SELECT FROM Members (username) WHERE username=?");
$stmt->execute($data);
if(mysql_num_rows($stmt)>=1)
{
echo"true";
}
else
{
echo "false";
}
Upvotes: 0
Views: 39
Reputation: 23992
You can fetch a boolean
result, from the sql query itself, with minor modification.
SELECT
count(username) > 0 as user_exists
FROM Members
WHERE username=?
In PHP script just read the result that has either a true
(1
) or false
(0
) as value.
Upvotes: 0
Reputation: 13474
Try this statement
SELECT * FROM Members WHERE username
or
SELECT username FROM Members WHERE username
Upvotes: 0
Reputation: 44844
SELECT FROM
Does not select anything.
You need to specify what you need to select or just * to select all
SELECT `username` FROM
OR
SELECT * FROM
Upvotes: 1