Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2003, 11:30 AM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
 
Old November 30th, 2003, 12:45 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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...
 
Old December 1st, 2003, 12:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Function returning an array rfstuck Pro VB 6 5 March 12th, 2008 07:35 AM
Function not returning value civa Access 5 January 17th, 2006 03:44 AM
Multi returning function reguengos Pro VB 6 2 March 3rd, 2005 01:48 PM
problem in Function returning Recordset pankaj_pp Classic ASP Professional 1 June 3rd, 2004 11:23 AM
Returning variables from a function starsol Beginning PHP 1 September 11th, 2003 12:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.