Check Username Availability Issue
I am just adding a new feature to my Joomla TPJOBS component although it's not a good/complete/active component but just I'm adding a user name Availability checker but its not wor
Solution 1:
<?php
defined('_JEXEC') or die('Restricted access');
$user = strip_tags(trim($_REQUEST['username']));
if(strlen($user) <= 0)
{
echo json_encode(array('code' => -1,
'result' => 'Invalid username, please try again.'
));
die;
}
// Query database to check if the username is available
$query = "Select a.username FROM #__users where username = '$user' ";
// Execute the above query using your own script and if it return you the
// result (row) we should return negative, else a success message.
$db =& JFactory::getDBO();
$result = $db->setQuery($query);
$available = mysql_num_rows($result);
if($available)
{
echo json_encode(array('code' => 1,
'result' => "Success,username $user is still available"
));
die;
}
else
{
echo json_encode(array('code' => 0,
'result' => "Sorry but username $user is already taken."
));
die;
}
die;
?>
Post a Comment for "Check Username Availability Issue"