Try:
select count(user_name) as usercount from $table where user_name = '$name'
Then extract the value 'usercount' from the recordset and if it's 0, none exists. If it's greater than 0, then it exists.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
You're executing the sql statement but you're not retrieving anything. You have to fetch the results into something like an associative array, so you use mysql_fetch_assoc(). Try this:
[php]
$Table = 'user';
$name = 'rootx';
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
$sqlquery = "SELECT COUNT(user_name) as user_name FROM $Table WHERE user_name = '$name'";
$results = mysql_query($sqlquery);
$user_count = mysql_fetch_assoc($results);
echo "current user name " . $_POST['usr_name'] . "
";
echo "query returned " . $sqlquery . "
";
echo "query returned " . $user_count['user_name'] . "
";
[/php]
Also, don't retrieve form variables as $_POST[whatever], use the apostrophes like I did in the code.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
There's an error in your SQL statement:
$sqlquery = "SELECT COUNT(usr_name) as FROM $Table WHERE usr_name ='$usr_name'";
The "as" statement assigns aliases to columns. In this case, your're not assigning an alias to the result that count(user_name) spits out. You need to put a name for a column's alias after the "as" but you skipped that and just wrote the "FROM."
Killer_Typo, check your PMs.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18