Jump to content

Function and mysql not working


Kaboom

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.