p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   Returning a result from a db function not allowed? (http://p2p.wrox.com/showthread.php?t=10671)

treycarroll March 17th, 2004 06:27 PM

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

Snib March 17th, 2004 07:18 PM

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---
----------

<><

treycarroll March 17th, 2004 07:53 PM

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


All times are GMT -4. The time now is 08:21 AM.

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