Kaboom Posted July 9, 2010 Share Posted July 9, 2010 I made a function for the emails but it's not working for some reason. I wanted to store my info in a db so the users can set their emails for paypal donations. well I got a problem. I used this code for my function: <?php function payments($email) { mysql_select_db($dbname, $db_id); $result = mysql_query("SELECT * FROM `config`"); while($row = mysql_fetch_array($result)) { echo $row['paypalemail']; } } ?> It's connecting because theres no db errors coming up and it loads db from a global.php file but i'm getting: Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/tyler/public_html/iblog/engine/payments.php on line 5 so "mysql_select_db($dbname, $db_id);" isn't a valid code anymore? all i'm getting is errors EDIT: if i take $dbname, off I get no errors but a blank page Link to comment https://forums.phpfreaks.com/topic/207213-function-and-mysql-not-working/ Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2010 Share Posted July 9, 2010 The function doesn't have access to the $dbname and $db_id variables, so what the function is getting is: mysql_select_db('', ''). You'd have to pass the db name and credentials to the function as parameters, or use an include()d file. See the manual on Variable Scope What is the purpose of the ($email) in the function declaration if you never use it in the function? Link to comment https://forums.phpfreaks.com/topic/207213-function-and-mysql-not-working/#findComment-1083406 Share on other sites More sharing options...
Kaboom Posted July 9, 2010 Author Share Posted July 9, 2010 Im just trying to get the email from the database, it's not done yet. And the main page index.php includes global.php which includes all the other pages needed to run the core files. For some reason (and its including the files..) it won't get the db. Link to comment https://forums.phpfreaks.com/topic/207213-function-and-mysql-not-working/#findComment-1083783 Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2010 Share Posted July 9, 2010 Im just trying to get the email from the database, it's not done yet. And the main page index.php includes global.php which includes all the other pages needed to run the core files. For some reason (and its including the files..) it won't get the db. A variable defined outside of a function is not available inside the function, and a variable defined inside a function is not available outside the function. Inside the function, $dbname and $db_id have no values. Link to comment https://forums.phpfreaks.com/topic/207213-function-and-mysql-not-working/#findComment-1083846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.