The following code is from within another function that i call from another page.
It creates an user id from 3 letters of first name a 3 letters of last name. ie JOEBLO if a user with this id already exists it replaces the 6th character with a 1
JOEBL1 and does so incementaly
JOEBL2 JOEBL3 JOEBL4
it worked fine but since it was put in a function it seems to fail!!
any ideas??
function checkid($var)
{$idquery = "SELECT * FROM crew WHERE id='$var'";
$result = mysql_query($idquery)
or die ("Couldn't execute id query.");
$row = mysql_fetch_array($result);
return $row;}
$formid = substr($firstname,0,3).substr($lastname,0,3);
if(checkid($formid) == TRUE)//IF MATCH IN DB ADD 1 UNTIL NO MATCH
{
$n = substr($formid,0,6);
$int = intVal(substr($formid,6));
do {
$int ++;
$newid = $n.$int;
}
while (checkid($newid) == TRUE);
$id = $newid;
}
else
{$id = $formid;}//IF NO MATCH OF ID IN DB, ID = FORMID