different varible types and how to convert.

ok I am working on a login script which generates a username for people who register.

What I would like to do is write it to add a number at the end in case the username is already taken such as btaylor1 is taken it generates btaylor2.

i am unsure how to do this or if it can be done. I have the script making the username I am just unsure how to add the number to the end or how to set an if statement to add the next number if the username is taken. any advice would be appreciated.

Here is the relevant code.

<?php $firstname = $_POST ['firstname']; $lastname = $_POST ['lastname']; $password= "test"; $arr1= $firstname; $lastname1= trim($lastname); $username= $arr1[0].$lastname1; $username= trim($username); $username= strtolower($username); $username= substr($username,0,7); $username= $username; $msg="Your name is $firstname $lastname, your Username is $username and your Password is $password."; ?>


php is converting variable types automaticly:
if u use the ‘.’ operator thay become strings:
while(!check_availability($username.$add)) $add++;

P.S.: this dosn’t even convert types. PHP may increment strings as well.

thanks for the help and advice.

Sponsor our Newsletter | Privacy Policy | Terms of Service