i have a php code to check if a user already exists in my db , but i would like it to go through jquery first .
This way instead of getting an error message on a new page , the user simply gets a message that the user already exists and can change the name.
Looks like this :
PHP CODE:
<?php
$link = mysqli_connect("localhost","root","","data1") or die("Error " . mysqli_error($link));
$usercheck = "csdcsdsdf";
$sanitizeduser= filter_var($usercheck, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$result = $link->query("SELECT username FROM users WHERE username = '".$sanitizeduser."' ");
$row_cnt = $result->num_rows;
if($row_cnt>0){
echo "User Exists";
}else{
echo "No User found";
}
?>
I'm using a predefined jquery code (this script : http://jqueryvalidation.org/)'
part of my jquery code to validate names :
names: function(value, element) {
return this.optional(element) || /^\w+$/.test(value);
},
Full Jquery code :
file 1 : http://jsfiddle.net/EjSbd/1/ (script.js)
file 2 : http://jsfiddle.net/qM4Uz/1/ (jquery.validate.js)
