validation - JQuery Validator plugin: Remote call not working -
i'm trying validate user name remote validation.
here js code
$('#form_reg').validate({ rules: { username: { minlength: 6, required: true, remote: { url:"validate_usr.php", async:false } }, }, highlight: function(element) { $(element).closest('.control-group').removeclass('success').addclass('error'); }, success: function(element) { element .text('ok!').addclass('valid') .closest('.control-group').removeclass('error').addclass('success'); } });
and php file
<?php include("bd_conex_mysql.php"); if (!empty($_request['username'])) { $usrname = $_request['username']; $checkname = mysqli_query("select count(*) cuentas ctausr = '".$usrname."'"); if($checkname->fetch_row() > 0){ echo 'false'; } else{ echo 'true'; } } else { echo 'false'; } ?>
it keeps accepting input if username taken.
i've changed php file
echo 'false'; ?>
and keeps validating input.
there no more support mysql_* functions, officially deprecated, no longer maintained , removed in future. should update code pdo or mysqli ensure functionality of project in future.
mysql_query
returns resource
rather result set. $checkname > 0
true. need fetch mysql_fetch_assoc
you should change query command mysqli_query
. , check results of $checkname->fetch_row()
http://us2.php.net/manual/en/mysqli.query.php
Comments
Post a Comment