I need to create a unique id for our users. I don\'t want to use an auto_incrementing id, because I don\'t want users to be able to guess how many users we have, or what the
If I understand you correctly, you are trying to let users choose their own unique ID from a table where there is not a user registered already. If this is the case then I would have my User table with userID and userName columns. Then return the userIDs where userName is still null.
$query = "SELECT userID, userName FROM User WHERE userName=''";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo $row['userID'];
}
If you want them to choose their own then run a query that has a where clause which will check whether a specific, user entered, number has a name. You can set the form up by using $_POST...
and then your checkID.php
$userName = $_POST['userName'];
$userID = $_POST ['userID'];
and then your query
$query = "SELECT userID, userName FROM User WHERE userName='' AND userID=$userID";
$result=mysql_query($query);
if ($result) {
echo "number is available";
$insert = "UPDATE User
SET userName=$userName
WHERE userID=$userID";
$inserted=mysql_query($insert);
if ($inserted) {
echo "you have been inserted as: ";
echo $userID;
echo $userName;;
}
}
Well I see this as being the basics for you. Obviously you will need to run some validation and error checks.
Hope this is what you're after. Let me know if not and will come back with something else.