Hi guys,
Problem's this: I can't work with sql in php...
So, I was wondering if anyone could help me out with a simple(?) user existence script.
DB: subscription
Table: users
Field: username
I need something like a function which returns true or false
This is the code that I already have, but it isn't working
Code:<? function querydb($query, $host, $user, $pass, $db) { $connid = @mysql_connect($host, $user, $pass) or die("Connection to the server failed"); @mysql_select_db($db) or die ("Connection to database failed"); $retval = @mysql_query($query) or die ("Query excecution failed"); return $retval; } function checkuser($username) { $username = strtolower($username); $q = "SELECT * FROM users WHERE username = '$username'"; $ret = querydb($q, 'localhost', 'root', '', 'subscription'); while ($row = mysql_fetch_assoc($ret)) { $myret = $row["username"]; } if ($myret != ''){ //echo "Username is unavailable"; echo $myret; } else{ //echo "Username is available"; echo $myret; } } ?>
Thanks for any help




Reply With Quote