It's one thing to find errors that I didn't foresee, and then fix them. It's another to find giant errors that occurred because I put a line in the wrong place.
First, I ended the current game, because it's been like 2 months. For some reason, all the previous games were given January's game ID, so they merged together. Had to go in and manually change the IDs to the right month, and eventually everyone got the right ID and displays properly.
Then, the main page indicated the wrong person had won last month, which had to do with how I was retrieving the previous game's information. Initially, I was pulling all records out of the table that matched a mathematical expression that I hoped was right, cycling through them in a loop until I grabbed the first entry (so, not even a full cycle of the loop), then abandoning the rest, just to get the name of the previous winner. It was a waste of a loop, and it didn't even work. I did not know that I could select "all records" out of the table "in reverse order" (most recent game first) "limited to just 1" record (or as many as I want), so only one record gets returned from the database, not potentially hundreds that I don't need, and it's just a name. Now, that's fixed, and the process takes about 25% of the lines of code that it did.
It was called to my attention that there was an error in the previous end-game, where shares weren't sold properly. Actually, it would seem they weren't sold at all. Well, that took some tinkering. First, I set up an output text file to store the status of the player data before it gets modified: their money, how many shares they were selling for how much, etc. Even the queries that were sent to the database to make the changes, just so I could see exactly what was going on.
It didn't work at first, and I couldn't tell why. I thought it was just how I was sending information to the file. I didn't know it wasn't doing anything at all. Ironically, the spot in question where nothing seemed to be happening was also the spot where shares were supposed to be sold. It's a FOR statement, so it starts at a certain number, and does things (sell shares) while counting the number of times it's done it, until it's done it enough times. Well, my upper-limit (the number of times to sell shares) is supposed to be the number of stocks that exist. Basically, it starts at stock 1, sells it, then goes to stock 2, sells it, repeat. When it gets to stock 7, it sees that doesn't exist, and it stops repeating.
Initially, I wanted this game to be expandable, have a variable maximum number of stocks, so I could add or remove them. So, everywhere in my code that it's told to cycle through the stocks, the upper-limit is a variable. At the start of any relevant page, it pulls out a row of the stock table, counts how many stocks there are, and then uses that number everywhere it's needed. And everywhere it's needed (except for the end-game script), it works. I did not realize that on that one page, where it matters the most, I tell it to count the number of stocks retrieved from the table *before* I retrieve any stocks from the table. So, the variable never gets set to anything. I don't even think it gets set to 0, it's probably just null, which is worse. So, my FOR loop, which wants to start at 1 and go to 6, starts at 1 and goes to nothing. Not 0, not a real number, just nothing. So it doesn't do anything at all, because it doesn't know how to count from 1 to a black hole where numbers are supposed to be.
Well, I say "supposed to be" because I know it's supposed to be a number, but the script doesn't. It isn't smart, if you don't tell it what goes in it, it doesn't know. Say you have a cup in your cupboard that you only drink milk out of. It might look different from your other cups, but it's still just a cup. Anything could be put in it, it doesn't care. It's a cup. So, if you say "pour from the pitcher into the cup" before you say "put a milk bag in the pitcher," then the cup is full of nothing, and regardless of how many times it's had milk in it, it will never assume it's supposed to have milk in it. It's a cup.
A bit of rearranging later, and it should all work fine. And if it doesn't, I'll be able to see why, and hopefully fix it. Can't do anything for the countless thousand shares that might have been lost this month, though.
Oh, I also told the script to stop immediately erasing all the previous month's player history (buying/selling/etc), but I don't think that will necessarily help anything. It doesn't show current amounts of shares, so that's pretty useless in the grand scheme of things. I'd have to make a new page to retrieve that information and total it and whatnot before I could make use of it.
Now hopefully I remember to uncomment all the database-updating scripts that I had to comment out in order to test the page (I tell it to display the queries on-screen rather than run them, so nothing gets changed, but everything runs as if it's changing things)