View Full Version : script to fix the effects of the credit-bug


gijs
03-04-2005, 07:37 AM
Jafo,

I still need a script to fix the effects of the credit-bug to automate adding the user ID to the user_id field of the credits table (of my allready 217- registrated users)

Or didn't I understood it well?

Bert

>In order for this to take affect for current users, you will need to add their >user ID to the user_id field of the credits table. If anyone needs a script to >automate this, let me know and I can write it up,

Jafo
03-04-2005, 03:10 PM
Open functions.php and add this function to the bottom of the page:

### Convert Users
function Convert_Users() {
$dbh = dbconnect();
global $dbprefix;
global $cred_register;
if (! $sth = mysql_query("SELECT id FROM " . $dbprefix . "users")) { die("Cannot Execute Query: ". mysql_error()); }
while ($statusi = mysql_fetch_array($sth,MYSQL_ASSOC)) {
if (! $stl = mysql_query("SELECT user_id FROM " . $dbprefix . "credits WHERE user_id = '$statusi[0]'")) { die("Cannot Execute Query: ". mysql_error()); }
$status = mysql_fetch_row($sth);
if ($status[0] == "") {
mysql_query("INSERT INTO " . $dbprefix . "credits (user_id, credits) VALUES ( '$statusi[0]', '$cred_register')") or die("Could Not Add user credits". mysql_error());
}
}
mysql_query("DELETE FROM ". $dbprefix ."credits WHERE user_id = ''");
}

Open index.php and right after this line:

Virtual_Cron();

Add this line:

Convert_Users();

I havent really tested this much, but it should work for you.

gijs
03-05-2005, 09:19 AM
Jafo,

Thanks. I did implement the code. When I want to modify the credits it gives an error:

"Credits must be numeric."

(Although with the new registrations it still works ok.)

Perhaps a question of 'credits' in stead of credits somewhere in the code you sent

{
mysql_query("INSERT INTO " . $dbprefix . "credits (user_id, credits) VALUES ( '$statusi[0]', '$cred_register')") or die("Could Not Add user credits". mysql_error());
}



Let me know. I'm not used to PHP and MySQL and afraid to corrupt the database

Bert

Jafo
03-06-2005, 11:52 PM
Make sure you defined the cred_register variable in the change settings screen to a numeric value.

gijs
03-07-2005, 07:17 AM
Jafo,

I'm not sure I understand your question... There is - and has always been so far - a 5. How/where can I define the cred_register variable elsewhere?

Bert

Jafo
03-07-2005, 01:23 PM
? You edit it in the change settings screen. What is your current setting for it now?

gijs
03-07-2005, 01:30 PM
Jafo,

5

Bert

Jafo
03-07-2005, 01:34 PM
So you get this error when you run the script I posted above or when you try to modify the credits some other way?

gijs
03-07-2005, 04:17 PM
Jafo,

I get the message when I try to increase manually the credits from 5 to 6 for instead.

Bert

PS
It's running on MySQL 4+. In another script we discovered the MySQL became more critical when you insert a number defined (by incident) as a character (defined as 'x' in stead of x ?) in a numerical field.

Jafo
03-07-2005, 06:49 PM
You have to enter a whole number when adding credits manually.

gijs
03-08-2005, 07:32 AM
Jafo,

The message disappeared. But the registrated members before the bug-fix have no credits. I don't know why. And I'm unable to upgrade them manualy. The script says 'Credits updated' but I don't see them. Like before.

I'm more or less lost now, because

- I did change the index.php and the functions.php according to the code you give
- the error does not reproduce
- the first members are still (again?) without credits (had them before as I remember well...)

- What to do now?

Bert

Jafo
03-08-2005, 02:48 PM
Actually I do see a bug in the Convert_Users function I wrote up, replace it with this one and redo the fix.

### Convert Users
function Convert_Users() {
$dbh = dbconnect();
global $dbprefix;
global $cred_register;
if (! $sth = mysql_query("SELECT id FROM " . $dbprefix . "users")) { die("Cannot Execute Query: ". mysql_error()); }
while ($statusi = mysql_fetch_array($sth,MYSQL_ASSOC)) {
if (! $stl = mysql_query("SELECT user_id FROM " . $dbprefix . "credits WHERE user_id = '$statusi[0]'")) { die("Cannot Execute Query: ". mysql_error()); }
$status = mysql_fetch_row($stl);
if ($status[0] == "") {
mysql_query("INSERT INTO " . $dbprefix . "credits (user_id, credits) VALUES ( '$statusi[0]', '$cred_register')") or die("Could Not Add user credits". mysql_error());
}
}
mysql_query("DELETE FROM ". $dbprefix ."credits WHERE user_id = ''");
}

gijs
03-08-2005, 04:32 PM
Jafo,

I replaced the code. There is not effect. 'Modify credits' seems to work - without any error message' - but there are no credits visible. Also I checked in the database the number of credits stay the same.

BTW: 'redo the fix' means replace, upload and run the index.php?

Bert

Jafo
03-08-2005, 06:06 PM
The number of credits will be the same, the problem is that the user id's were not populated. Did you check that each entry has a user id?

gijs
03-08-2005, 06:46 PM
Jafo,

Yes, I think so: under 'salt'?
4 Forever w.meijxxx@chello.nl e10adc3949ba59abbe56e057fxx5674xxx 1109635330 confirmed 1109537965 NULL

Did I run this fix indeed correctly?

Bert

Jafo
03-08-2005, 11:13 PM
Salt? Credits are stored in the table called credits, not user.

gijs
03-09-2005, 03:59 AM
Jafo,

Sorry, you asked me: Did you check that each entry has a user id? I misunderstood.

Watching the table below I understand now better that you mean each 'credit entry'. So the answer is 'no'. All the old user_id's mention the same '1'. See below.

(Apparently the credits amount at register (cred_register) was originally on '3'.?)

class_credits table:

id user_id credits
40620 230 5
20508 229 5
927 228 5
835 227 5
834 226 5
224 225 6
223 1 3
222 1 3
221 1 3
220 1 3
219 1 3
218 1 3


Bert

Jafo
03-09-2005, 06:13 AM
So those users should have 3 (or 5) credits each.

gijs
03-10-2005, 06:17 PM
Jafo,

Yes, three for all is ok. But remember the problem is that I have 200 registrated users with user_id=1... I just do not see the credits of all the users with the user_id =1 (registrated before the bug-fix) appearing in the 'user details'. That box remains empty (and impossible to update).

Bert

gijs
03-10-2005, 06:31 PM
Jafo,

Watching well this table columns below it seems that something went wrong running the bug-fix script. On the 6/7 line the user_id takes suddenly the place of the id, and the 1 is 'extra' (?). The id seems to miss...

You you think you are able to repare, or do I have to delete all the users and register them all again?

id user_id credits

40620 230 5
20508 229 5
927 228 5
835 227 5
834 226 5
224 225 6
223 1 3
222 1 3
221 1 3
220 1 3
219 1 3
218 1 3

Jafo
03-10-2005, 08:06 PM
You know what? Just delete the users who are having the issue and have them re-register. I dont think I can fix what has happened here..

gijs
03-11-2005, 03:23 AM
Jafo,

That means I have to delete that 225 registrated users after all...
Does the 'fix-code' you give me and I added has any other function or can I delete it as well?
Not so happy, hours off work to reregistrate. Well, we will see. It was also your time. Bad luck...

Bert