Jquery file
$(document).ready(function() {
$('input.textinput3').each(function() {
$(this).rules("add",
{
required: true,
minlength: 3,
remote: "report/user_check.php",
messages: {
required: "Type Serial number!",
minlength: jQuery.format("Please, at least {0} character are necessary"),
remote: jQuery.format("{0} is already taken"),
// remote: 'This email address has already been used'
}
})
});
// initialize the validator
$('form.warregform').validate();
});
My PHP files
include("db.class1.php");
if (isset($_POST['wproserial'])) {
$db = new mysqldb();
$db->select_db();
for ( $i=0;$i<count($_POST['wproserial']);$i++) {
{
$wproserial = $_POST['wproserial'][$i];
}
}
$query = "SELECT EXISTS (SELECT * FROM products WHERE SerailNo='mysql_real_escape_string($wproserial)')";
if($db->num_rows($db->query($query)) < 1) {
return true;
}else {
return false;
}
}
I can't check validation with existing database, this serial no. is already register or not. every input data is showing message "is already taken". so i can't submit. My Serial no input field is unlimited.
My Html files
default show
<input name="wproserial[]" id="wproserial0" type="text" value="" class="textinput3 " autocomplete="off">
After Add
<input name="wproserial[]'+i+'" id="wproserial'+i+'" type="text" value="" class="textinput3">
The remote validation expects your server side script to return json. You should do the following instead of just returning true
or false
:
if($db->num_rows($db->query($query)) < 1) {
$valid = 'true';
} else {
$valid = 'false';
}
echo json_encode($valid);
Change your query
$query = "SELECT EXISTS (SELECT * FROM products WHERE SerailNo='mysql_real_escape_string($wproserial)')";
to this
$query = "SELECT * FROM products WHERE SerailNo='".mysql_real_escape_string($wproserial)."'";
try this
$query = "SELECT EXISTS (SELECT * FROM products WHERE SerailNo='".mysql_real_escape_string($wproserial)."')";
instead
$query = "SELECT EXISTS (SELECT * FROM products WHERE SerailNo='mysql_real_escape_string($wproserial)')";