I have spent the last 8 hours (seriously) trying to figure out this stupid
piece of code, and it's just beyond me why it doesn't work. I hope someone
here can help, or even follow the code.

I have a form where the user inputs information - the code below is the
error checking for one of the fields. The first IF statement just checks
that the filed is not empty.

The first ELSEIF checks a function to see if the user is already in the
mysql database and returns the letter T, D or S.  ** This part works fine.

If the first ELSIF is not = to T then the second ELSEIF is checked to see if
the letter returned is D. I have checked over and over and over and over and
the letter D is being returned (I have checked the third ELSEIF and it is
the same). It appears like they are just being ignored.

Either I am just not getting the concept, or there is something seriously
weird going on.

Any help in solving this mystery is truely appreciated.

if (empty($form["name"])) { $error["name"] = "*"; $message["name"] =
"Required field!";
}
elseif($duplicate = duplicate_name($form["name"]) == "T") {
     $error["name"] = "*"; $message["name"] = "Screen name already used!";
}
elseif ($duplicate == "D") {
     $error["name"] = "*"; $message["name"] = "Database error - Please try
again in a few moments!";
}
elseif ($duplicate == "S") {
    $error["name"] = "*"; $message["name"] = "Server error - Please try
again in a few moments!";
}


function duplicate_name($name) {

if (!($connect = @mysql_connect($serverhost,$serveruser,$serverpass))) {
**** These are all defined above - not included here.
 $server_error = "S";
}

if ([EMAIL PROTECTED]($databasename)) {
 $server_error = "D";
}

if($server_error) { $duplicate = $server_error;
}
else
{
$query = "SELECT name FROM $tablename WHERE name = '$name'";

if(!$query) { $duplicate = "D";  }

else {
    $result = mysql_query($query);
    $line = mysql_fetch_array($result);

if($line['name'] == $name) { $duplicate = "T"; }

mysql_free_result($result);
mysql_close($connect);

}
}

echo $duplicate;   *****  This shows that the variable $duplicate contains
T, D, or S.

return($duplicate);
}



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to