0

查询文件

$(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();    

});

我的 PHP 文件

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;
    }   
} 

我无法检查现有数据库的验证,这个序列号。是否已经注册。每个输入数据都显示消息“已被占用”。所以我不能提交。我的序列号没有输入字段是无限的。

我的 HTML 文件

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">
4

3 回答 3

1

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)."'";
于 2013-08-01T09:07:16.783 回答
0

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)')";
于 2013-08-01T09:07:32.923 回答
0

远程验证期望您的服务器端脚本返回 json。您应该执行以下操作,而不仅仅是返回trueor false

if($db->num_rows($db->query($query)) < 1) {
    $valid = 'true';
} else {
    $valid = 'false';
}

echo json_encode($valid); 
于 2013-08-01T09:00:54.693 回答