The first three steps are just as you guessed; after that, things get a tad bit different; I'll try to break the whole thing down as much as possible. I'm not sure this is quite the format you asked for, but I hope it will still be understandable and helpful.
"Step 1" is very complicated, and I don't think it will make sense in its own right without knowing what happens afterwards, so I would recommend you start reading at "Step 4", then go back to the top after you've read to step 6.
Step 1.The user visits the page, "numbertest.php". The page logs in to the server and selects the database we'll be using for this, "test".
<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
echo "Initial connection to the server was successful!<br/>";
mysql_select_db("test") or die(mysql_error());
Step 2.Having selected the "test" database, it selects the first and second items in the "storage" table and records their values for future use in the "$storage" variables.
$result = mysql_query("SELECT * FROM storage WHERE ID = '1'");
$row = mysql_fetch_assoc($result);
$storage = $row['numbers'];Step 3.It now updates the item in the "game" table that has an ID that is equal to the number that is stored in the first item in "storage". The "game" table item's "point" total is increased by 1.
$result = mysql_query("UPDATE game SET Points=points + 1 WHERE ID = '$storage'");The other, parallel code shown in my first post works the same way, except that it decreases the "game" table item's "point" total, instead of increasing it.
Step 4.The two random numbers are generated, as you mentioned. The numbers are equal to IDs in the "game" table, and it displays those items' contents. Two forms appear, each displaying only a single submit button.
Step 5.This is where things start to get a little bit complicated (everything else you said up to this point was correct).
The user clicks one of the submit buttons (we'll say it's the first button, as their code functions almost exactly the same). Button #1 has this code:
<?php
echo '<form action="numbertest.php" method="POST"><table>';
echo '<tr><td><input type="submit" name="SubmitForm" value="$test"></td></tr>';
echo '<form>';
if (!isset($_POST['SubmitForm'])) {
} else {
$result = mysql_query("UPDATE storage SET numbers='$test' WHERE id = '1'");
$result = mysql_query("UPDATE storage SET numbers='$test2' WHERE id = '2'");
}
?>
Button #1 submits "SubmitForm" through POST. As soon as "SubmitForm" is set, then it updates the first and second items in the "storage" table, filling the contents of the first item in "storage" with the first random number (the one that was generated in step 1), and putting the second number in the second item.
... or at least, that is what it is supposed to do. There's a glitch in this process, which I will attempt to elaborate on after I've finished talking about the rest of the code.
Step 6.The page (apparently) refreshes. Go to Step 1.
The GlitchSo far, the code looks workable (to me), but there's a major hangup during step 5 of the process.
Button #1 (or #2) does submit two numbers through POST, but they don't seem to be the right ones; sometimes it gives the server the opposite numbers.
After further study, I have concluded that my original explanation of the problem was wrong. In fact, the problem seems to come up every time the user switches buttons -- as long as you keep pressing the same button, it will always work as intended, but when you switch from one button to the other, it initially gives an incorrect result (but it will begin to work correctly if you keep pressing it as the numbers change). Thus, you can consistently get the buttons to work incorrectly by alternating between them.
I know this is a convoluted explanation. I created a set of pictures to try to explain them, but unfortunately it seems that images in posts aren't allowed on the forum right now. I'll try to recreate them in text-based form so that they might still help you. The things in parentheses are the buttons.
Initial connection to the server was successful!
ID: 2, Points:0
ID: 1, Points:0
($test)
($test2)
ID 2 is on top, 1 is on the bottom. I'll click the top button (for the top ID). I have the server start out at 0 in the "storage" table items' contents, so it takes one click before the server seems to start recording user clicks.
Initial connection to the server was successful!
ID: 2, Points:0
ID: 2, Points:0
($test)
($test2)
An annoying artifact of my random number generation system is that it sometimes gives me the same IDs twice in a row. I haven't fixed this yet, and it bogs down the testing process. Hitting the top button again.
Initial connection to the server was successful!
ID: 2, Points:0
ID: 1, Points:0
($test)
($test2)
Back to square one here; clicking top button.
Initial connection to the server was successful!
ID: 1, Points:-1
ID: 2, Points:1
($test)
($test2)
As you can see, the top button actually works here. However, when I click the bottom button, it will produce the opposite of its intended effect and bring both numbers back down to 0.
Initial connection to the server was successful!
ID: 1, Points:0
ID: 3, Points:0
($test)
($test2)
ID 1 is now back at 0 points. If this code functioned properly, it would be at -2. When I click the top button, it will increment ID 3 by 1 point, though that's the opposite of what I intended.
Initial connection to the server was successful!
ID: 3, Points:1
ID: 1, Points:-1
($test)
($test2)
So it does seem I now have a better understanding of how the form submissions are going haywire. The only question is why it does this, and that's one I can't answer.
I hope this new post was able to shed a little light on the situation. I know my writing is often difficult to read, so if there's anything that doesn't make sense, please ask and I'll try to explain it.
Thanks very much for your attention.