Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Closed Thread
MySQL is being stupid...
Old 07-25-2010, 07:47 PM MySQL is being stupid...
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 818
Name: Scott
Location: Ontario
Trades: 0
Alright so I have this code:

PHP Code:
function userExists($userSet) {
    
$userE mysql_query("SELECT userID FROM $DBmemberTable WHERE username = '$userSet'");
    
$userE mysql_fetch_array($userE);
    
$userE $userE[0];
    echo 
"-- $userE --";
    return 
$userExists;

It's a function that grabs the userID from $DBmemberTable where the username is $userSet.

I have $DBmemberTable="members"; in my config.php file, which is included with a standard include(''); statement to the file holding the userExists function.

The database is opened and selected, so that's working fine. What it just can't figure out is what $DBmemberTable is, even though it's in teh include file with nothing fancy. It works everywhere else on my site.

Do includes not work in MySQL? Can you not put MySQL statements in functions? What's the deal
What really bothers me is if I put $DBmemberTable="members"; right inside the function, it works. But it doesn't seem to know what $DBmemberTable is outside of the function. I can even copy the include('config.php'); statement right into the function and it works, but how can I get it to work without having to call on something that's already been called?

Thanks,

_PG
__________________
Check out my
Please login or register to view this content. Registration is FREE

Last edited by Physicsguy; 07-25-2010 at 07:48 PM..
Physicsguy is online now
View Public Profile
 
 
Register now for full access!
Old 07-25-2010, 08:01 PM Re: MySQL is being stupid...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,488
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Do includes not work in MySQL
Nope, only in PHP, ASP etc etc.

Quote:
Can you not put MySQL statements in functions?
Yes. provided the database connection variables are global in scope.

Quote:
But it doesn't seem to know what $DBmemberTable is outside of the function.
That's because variables declared inside a function are local in scope to the function so are inaccessible outside of it.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 07-25-2010, 08:10 PM Re: MySQL is being stupid...
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 818
Name: Scott
Location: Ontario
Trades: 0
Ahh, thank you Chris, to the rescue again

Thanks
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is online now
View Public Profile
 
Closed Thread     « Reply to MySQL is being stupid...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34190 seconds with 12 queries