Im trying the login with twitter functionality.
if twitter returned username already exist in my database I am creating a new username for that user.
following is my code
class myclass{
function getusername($username){
global $db;
$sql ="select * from us_signup where username ='".$username."'";
echo $sql;
$results = $db->rawQuery($sql);
if(!empty($results)){
echo 'if';
print_r($username);
$username = $username.rand(0,1000);
$this->getusername($username);
}else{
echo "else";
print_r($username);
return $username;
}
}
function insertintodb(){
echo "oldusername : ".$username;
$username = $this->getusername($username);
echo "newusername : ". $username;
}
}
1) insertintodb calls getusername with currentusername got from twitter
2) getusername checks it in the database
3) if the username exist in the database then it adds a random number to it and then calls itself
4) if the username doesn't exist in the database it returns the username
5) getusername calls itself until it finds username which doesn't exist in the database
My problem is
I am calling the function getusername with 'sugumar' which exist in the database
so it calls itself again with newusername 'sugumar1234'(1234 is a random number can be anynumber). 'sugumar1234' doesn't exist in the database so I expect it return 'sugumar1234' but it returns nothing
following the ouput of print
oldusername : sugumarselect * from us_signup where username ='sugumar'ifsugumarselect * from us_signup where username ='1234'else1234newusername :