过去一周我一直试图解决这个问题。知道这里有其他问题已经回答了类似的问题,但却无法使其发挥作用。
这是我用于远程验证的jQuery:
sponsorcode: {
required: true,
remote: {
url: "../process/conn.php",
type: "POST",
async:false,
data: {
sponsorcode: function(){
return $("#sponsorship").val();
}
}
}
},
这是数据库检查(conn.php)(它还将'used'列标记为1,因为每个代码只能使用一次:
// Make sure a sponsor code was provided
if (isset($_POST['sponsorcode']) && !empty($_POST['sponsorcode'])) {
// Escape the sponsor code to prevent SQL injection
$code = mysqli_real_escape_string($link, $_POST['sponsorcode']);
// Mark sponsor code as used if possible
$sql = 'UPDATE teachercodes SET used=1 WHERE sponsorcode="' . $code . '"';
mysqli_query($link, $sql) or die(mysqli_error($link));
if (mysqli_affected_rows($link)) {
// Sponsor code hasn't been used before and is valid
echo (json_encode(true));
} else {
//show that the query was successful but that the client was not found
echo (json_encode(false));
}
//free the MySQL result set
mysqli_free_result($result);
} else {
//the form was either not submitted or submitted with an empty value.
echo (json_encode(false));
}