I hate when I have to resort to bothering people with questions. I however have pulled my hair out on this one. Basically I am trying to get the first part of the code for checking a username against the db.
Description:
I have a user add feature, I want to check to make sure the user doesn't already exist, if so echo it. If not add it.
I think what has complicated the issue, for me anyway, is the fact I am using PHP SELF with a form.
I can't seem to get the else function to work within an if:. The code will echo that it exists if it is already there, but won't do a thing if it's not..:
if (isset($useradd)) {
require("config.php");
mysql_select_db($DB_NAME);
$userquery = mysql_query("SELECT username FROM user WHERE username = '".$username."'");
// was it correct?
$exist = mysql_num_rows($userquery);
while ($v = mysql_fetch_array($userquery)) {
$uname = $v[0];
if($exist == 1) {
echo "The username,<B>'$uname'</B> already exists.";
} else {
echo "It doesn't exist";
}
}
}