Password table with MySQL...
Posted: Sun Aug 10, 2003 12:18 pm
Hello everybody!
I have this type of table.
The number X indicates next available password.
Works this way: firs take the value of X (X= select password from table_name where ID=1), which points to the next password. Then SELECT password from table_name where ID=X; And then UPDATE this table - I need to update password++, where ID=1 (so that it points to the next password)
But the problem is obvious - two persons making simultaneous requests for a pass obtain the same value of this X (before it's updated) and therefore get the same password, which is anacceptable. I have solved this problem easily but sertainly not efficiently and I want to see someone eslse's solution - HOW IT SHOULD BE DONE, please step-by-step, I'm new to PHP.
I have this type of table.
Code: Select all
+------+----------+
| ID | password |
+------+----------+
| 1 | X |
+------+----------+
| 2 | 43543543 |
+------+----------+
| 3 | 34656546 |
+------+----------+
| 4 | 74378286 |
+------+----------+
| 5 | 54786588 |
+------+----------+
| ... | ... |
+------+----------+
| ... | ... |
+------+----------+The number X indicates next available password.
Works this way: firs take the value of X (X= select password from table_name where ID=1), which points to the next password. Then SELECT password from table_name where ID=X; And then UPDATE this table - I need to update password++, where ID=1 (so that it points to the next password)
But the problem is obvious - two persons making simultaneous requests for a pass obtain the same value of this X (before it's updated) and therefore get the same password, which is anacceptable. I have solved this problem easily but sertainly not efficiently and I want to see someone eslse's solution - HOW IT SHOULD BE DONE, please step-by-step, I'm new to PHP.