PDA

View Full Version : getUserLink($user) function



bobbywise
09-30-2003, 09:08 AM
Hi,

I stumbled across an error while viewing favorites.php, and is due to the fact that the function it calls from style.php is not looking at the correct table in the database.

The following line is at fault in the function getUserLink($user) within style.php:


$sql = "SELECT user_name, isAgent, ID FROM UserDB WHERE (ID = $user)";


This is because all the database tables are prefixed by default_

So there are two ways to fix this line.

1. By adding default_ so it reads as follows:


$sql = "SELECT user_name, isAgent, ID FROM default_UserDB WHERE (ID = $user)";


2. By adding the actual configuration prefix, " . $config[table_prefix] . " so it reads as follows:


$sql = "SELECT user_name, isAgent, ID FROM " . $config[table_prefix] . "UserDB WHERE (ID = $user)";


Solution 1 works fine. But for some bizarre reason solution 2 still produces an SQL error similar to the following:

SELECT user_name, isAgent, ID FROM UserDB WHERE (ID = '6')

This means that for some reason in solution 2, the configuration prefix, " . $config[table_prefix] . " is being ignored. I am really confused as to why this is the case because the configuration prefix, " . $config[table_prefix] . " works fine in all of the other functions defined.


Any ideas ?

Rob.
http://www.robertwisbey.com

greengiant
09-30-2003, 10:21 AM
thanks for the bug report, i will get a fix up this week. TO fix the $conifg issue, put the following line at teh top of that function.

global $config;

the_sandking
09-30-2003, 10:30 AM
Solution 1 works fine. But for some bizarre reason solution 2 still produces an SQL error similar to the following:

SELECT user_name, isAgent, ID FROM UserDB WHERE (ID = '6')

This means that for some reason in solution 2, the configuration prefix, " . $config[table_prefix] . " is being ignored. I am really confused as to why this is the case because the configuration prefix, " . $config[table_prefix] . " works fine in all of the other functions defined.


Any ideas ?

Rob.
http://www.robertwisbey.com



Yes, there is a missing GLOBAL...

about 2 lines above the the $SQL= statement the global variables for this function are defined...


global $conn, $lang;

These 2 global values defined are the MySQL connection, and the Language variable arrays

However, the variable array item you are calling in the $SQL= statement using "$config[table_prefix]" isn't available.. It's a $config variable from the $config array. .

To use these $config variables, you must include $config in the globals within the function if you want to use variables from it's array.



global $conn, $lang, $config;

That should allow you to use the "correct" variable in the $SQL= statement.

bobbywise
10-02-2003, 08:27 PM
Doh !

I missed the global :shock:


Thanks for pointing it out.

Cheers,

Rob
http://www.robertwisbey.com