如何验证easyui中已存在的用户名?

时间:2013-04-03 03:52:22

标签: php jquery jquery-easyui

MY JS

<script type="text/javascript">
$.extend($.fn.validatebox.defaults.rules, {  
                remote: {
                type: "POST",
                success: function(result){
                var result = eval('('+result+')');
                    if (result.success){

                    } else {
                        alert('already exists');
                    }  
                }  
            } 
        }  
</script>

<input name="username" class="easyui-validatebox"  validType="remote['./include/checkusername.php','username']">

PHP代码

<?php
/* check if email is already registered */

//connect to db using mysqli

include 'connection.php';

$usern = $_POST['username'];

if(isset($_POST['username']))
{
$sql = "SELECT * FROM tblcustomers WHERE username = '"+$usern+"'";
$result = mysql_query($sql);   

if($result->num_rows == 0){
    echo "true";
}
else
{
    echo "false";
}

}
else
{
echo "false"; //invalid post var
}

?>

0 个答案:

没有答案