Closed Thread
MySQL is being stupid...
Old 07-25-2010, 06:47 PM MySQL is being stupid...
Physicsguy's Avatar
Dividing by zero

Posts: 367
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
__________________
ReviewCraft - Minecraft Server Review | MyWebForums
Code:
Warning: Division by zero

Last edited by Physicsguy; 07-25-2010 at 06:48 PM..
Physicsguy is offline
View Public Profile Visit Physicsguy's homepage!
 
 
When You Register, These Ads Go Away!
Old 07-25-2010, 07:01 PM Re: MySQL is being stupid...
chrishirst's Avatar
Super Moderator

Posts: 32,241
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
Code Samples | Crowded Nightclub? | Random Ramblings
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 07-25-2010, 07:10 PM Re: MySQL is being stupid...
Physicsguy's Avatar
Dividing by zero

Posts: 367
Name: Scott
Location: Ontario
Trades: 0
Ahh, thank you Chris, to the rescue again

Thanks
__________________
ReviewCraft - Minecraft Server Review | MyWebForums
Code:
Warning: Division by zero
Physicsguy is offline
View Public Profile Visit Physicsguy's homepage!
 
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.12080 seconds with 13 queries