p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   Function not returning anything... (http://p2p.wrox.com/showthread.php?t=6705)

goatboy November 30th, 2003 11:30 AM

Function not returning anything...
 
Can someone tell me why, when I call this function with "checkUserDb($user);" it's not returning anything for $matched ?
Am I missing something, because it makes no sense to me.


function checkUserDb($submittedName) {
    global $hostname, $username, $password, $dbName;

    if (!($connection = @ mysql_connect($hostname,$username,$password))) {
        die("Could not connect to host.");
    }

    if (!(mysql_select_db($dbName, $connection))) {
        die("Could not connect to database.");
    }

    $nameQuery = mysql_query("SELECT * FROM db_users");
    while ($checkRow = mysql_fetch_array($nameQuery)) {
        $formName = $checkRow['user'];
        if ($submittedName == $formName) {
            $matched = "yes";
            break;
        }
        else {
            $matched = "no";
        }
    }

    mysql_close($connection);
}


If only stupidity was painful...

goatboy November 30th, 2003 12:45 PM

If stupidity was painful, I'd be doing a lot of screaming. I was attempting to call the function, not check the result against anything. When I used
Code:

$match = checkUserDb($user);
everything worked fine.

For all the other newbs out there :D



If only stupidity was painful...

nikolai December 1st, 2003 12:34 PM

You are also missing a return statement in your function -- technically, your assignment statement ($match = checkUserDB($user)) shouldn't assign anything because checkUserDB() doesn't return anything...

I can only assume that the last line of your function is now:

  return $matched;


Take care,

Nik
http://www.bigaction.org/


All times are GMT -4. The time now is 07:48 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.