I _THINK_ this is to do with scope.
If you say
elseif ($duplicate = ...)
{
}
and this is the first use of the variable $dublicate, then $duplicate goes
out of scope at the end of the right brace.
I could be wrong about that, but it's worth a try. See what happens if you
declare the variable $duplicate _before_ the first if(...). For example:
$duplicate = "";
if (...)
...
Jill
-----Original Message-----
From: ODCS [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 02, 2003 6:26 AM
To: PHP Windows
Subject: [PHP-WIN] I really don't understand this?
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
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php