I have a user input of first and last name, which my scrpit creates $fromid from. It is made of 3 letters of first name and 3 letters of last name, ie oliwar, chrlew, jeschr
In order to check if the user id is already taken i have written the following script.
The function checkid($id) sends a query to the db using the id and if it returns true a new id is needed.
The do while is where my problem lies it adds 1 to the end of $formid, however if there is already an id with a number on the end, it loops by trying 1 on the end of formid each time, always returning a negative result.
I figure i need to replace the ++ line with code that adds 1 each time it is run.
if(checkid($formid) == TRUE)//IF MATCH ADD 1 TO FORMID
{echo "ID MATCHES AN ID IN DB</br>";
/*
do
{
$n = substr($formid,0,6);
$int = substr($formid,6,1);
$int ++;
$newid = ($n.$int);
}
while ((checkid($newid) == TRUE));
*/
$id = ($newid);}
else
{$id = $formid;}//IF NO MATCH OF ID IN DB, ID = FORMID
echo $id;
Advance thanks