Hi, im still in the early learning stages, banging my head against walls looking for clues. Iv been reading the manual to no avail.
im building a user log in system based on the phpAcadamy tutorial 'Register & Login'. They use mysql_connect in the tutorial, but I am using a PDO connection to mysql.
i am making my first function, user_exists, which queries the username column of my table for names that match the POSTed $username, then returns a true or false if it is found.
here is my testing code:
<?php
$host = "localhost";
$username = "mholberg_skroovy";
$password = "*omitted*";
$dbname = "mholberg_skroovytest";
$db = new PDO("mysql:host={$host};dbname={$dbname};", $username, $password);
function user_exists($username) {
$query = $db->query("SELECT `users`.`username` FROM `users` WHERE `username` = '$username'");
return($query, 0) == 1) ? true : false; //???
}
if (user_exists('junkomatic') === true) {
echo 'exists';
}
die();
?>
The if statement at the bottom should test the function above it. The line with ??? is the line that is obviously wrong. Im getting an error on the ','
Any input/explanation would be hugely appreciated.