我正在制作一个小项目,现在正在研究注册模块。我使用 Jquery .post
方法调用页面来检查输入的数据是否正确。一切正常,但如果数据不正确,它会显示消息,但也会注册用户。这是js代码:
$("#name").keyup(function(){
$.post("check/user_check.php" , {
username: $("#name").val()
}, function(response) {
$("#validateTips").fadeIn("slow");
$("#validateTips").html(response);
});
});
user_check.php 是:
<?php
include "config.php";
$user = $_POST['username'];
$user_query = mysql_query("SELECT username FROM users WHERE username='$user'");
if(strlen($user) < 3)
{
print "<span id='wrong'>username is too short</span>";
}
还有其他情况,时间太长并且已经采取了,但我想你明白了重点是什么。所以问题是,如果 user_check.php 打印用户名不正确,该怎么做才能阻止注册?
最佳答案
返回错误信息后停止执行:
if(strlen($user) < 3)
{
print "<span id='wrong'>username is too short</span>";
die(); //Stop right here
}
关于javascript - 使用 Jquery .post 方法进行验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19878350/