Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 30th, 2003, 11:30 AM
Registered User
 
Join Date: Nov 2003
Location: , , .
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...
Reply With Quote
  #2 (permalink)  
Old November 30th, 2003, 12:45 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
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...
Reply With Quote
  #3 (permalink)  
Old December 1st, 2003, 12:34 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
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/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:32 PM.


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