I'm going through a vid tutorial on creating a user reg & login form in php and mysql.
The following script should echo 'exists' on the login.php form, however just shows a blank (indicating the user does not exist, when it does and s in fact the only username on the DB)
<?php
function user_exists($username) {
$username = sanitize($username);
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
return (mysql_result($query, 0) == 1) ? true : false;
}
?>
The login form portion of code goes as follows:
if (user_exists('andy') === true) {
echo 'exists';
}
die();
Am I missing some syntax or something obvious?? here is a link to the vid tutorial if it helps http://www.youtube.com/watch?v=Til3oVNlho4
mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the warning? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. – tereško 16 mins agomysql_
, and notmysqli
, so why keep the OP on the same track? ;) – Fred 13 mins ago