RE: [PHP] Returning a variable from a function problem
| From: | Ford, Mike [LSS] | Date: | Wed, 02 Apr 2003 13:11:13 +0000 |
| Subject: | RE: [PHP] Returning a variable from a function problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-141979@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: ODCS [mailto:odcs@rogers.com]
> Sent: 02 April 2003 08:10
>
> 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 and works fine.
>
> Then I check a function I made to see if the user is already
> in a mysql
> database and the function returns 0, 1, or 2 depending on the various
> conditions. The first elseif works as I would expect - but it
> seems that the
> next two elseif's are just being ignored.
>
> Could someone possibly explain what I have wrong here. Thanks
>
> if (empty($form["name"])) { $error["name"] = "*";
> $message["name"] =
> "Required field!";
> }
> elseif($duplicate = duplicate_name($form["name"]) == 0) {
This statement assigns the result of the comparison duplicate_name($form["name"]) == 0 to
$duplicate (giving FALSE if this branch isn't executed, and so never satisfying the tests for 1
or 2 below). I suspect that what you mean is:
elseif(($duplicate = duplicate_name($form["name"])) == 0) {
> $error["name"] = "*"; $message["name"] = "Screen name
> already used!";
> .
> }
> elseif ($duplicate == 1) {
> $error["name"] = "*"; $message["name"] = "Database
> error
> - Please try
> again in a few moments!";
> }
> elseif ($duplicate == 2) {
> $error["name"] = "*"; $message["name"] = "Server error -
>
> Please try
> again in a few moments!";
> }
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211