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 March 17th, 2004, 06:27 PM
Registered User
 
Join Date: Jun 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Returning a result from a db function not allowed?

Hey everybody,

Can anybody see what is wrong here? I can't get any error messages to get a clue where to start. The "new part" is the function select_result(). Can you not pass back a result? Why don't I get at least some error message? I don't even see Hello World (HTML at the bottom). Very frustrating indeed.

Thanks,

Trey

<?
require_once("/home/mysite/db/dbDefinitions.inc"); // ;)

 function db_connect()
    {
    global $db_host, $db_user, $db_pwd, $db_name;
    $link_id = mysql_connect($db_host,$db_user,$db_pwd);
    mysql_select_db($db_name,$link_id);
    return $link_id;
    }

 function select_result($strSQL){
    $link = db_connect();
    $result = mysql_query($strSQL, $link);
    return $result;
    }

 function UID_inuse($uid){
    $result = select_result("SELECT COUNT(*) AS count FROM parent WHERE user_name='$uid'");
    $fetch = mysql_fetch_array($result,$link);
    return ($fetch['count'] == 0)?false:true;;
    }

if(UID_inuse("treyc"){
    echo "User ID is in use";
    }
else{
    echo "User ID not in use";
    }

?>
Hello world

---------------
Trey Carroll
 
Old March 17th, 2004, 07:18 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try adding "or die(mysql_error);" after every mysql function.

Also I noticed function UID_inuse has two ";" in a row...

Also I've heard its more reliable to open PHP with <?php and not <? but I don't remember where (or maybe it was about an older version...)

HTH,

----------
---Snib---
----------

<><
 
Old March 17th, 2004, 07:53 PM
Registered User
 
Join Date: Jun 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. I haven't touched php in months and so I'm rusty. Seems like my Host had completely turned off error reporting in php.ini so I wasn't getting any clues. There are several dumb errors. You CAN return a result set from a function. Thanks for the help.



---------------
Trey Carroll





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Returning Dodgy Result In Distress Visual Studio 2005 4 January 12th, 2007 01:19 AM
Function not returning value civa Access 5 January 17th, 2006 03:44 AM
UDF: allowed in one DB but not another??? ea SQL Server 2000 2 January 18th, 2005 03:14 PM
Function not returning anything... goatboy Beginning PHP 2 December 1st, 2003 12:34 PM
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.