我有一个简单的脚本,即使 PHP 脚本运行成功,也会导致错误。
PHP
require('/connect.php'); //Has my $link variable
if(isset($_POST['pass'])){
$user = $_POST['user'];
$oldpass = md5(urldecode($_POST['op']));
$newpass = md5(urldecode($_POST['np']));
$q = "SELECT * FROM `nht_users` WHERE usr = '".$user."' AND pass = '".$oldpass."'";
$r = mysqli_query($link,$q);
$n = mysqli_num_rows($r);
if( $n > 0){
$u = "UPDATE `nht_users` SET pass = '".$newpass."' WHERE usr = '".$user."'";
mysqli_query($link,$u);
}
else{
echo json_encode('FALSE');
}
}
jQuery
$('#pass-submit').click(function() {
var npp = $('#npp').val(),
np = $('#np').val(),
data = $('#pass-form').serialize(),
url = 'http://www.<?php echo DOMAIN; ?>/functions.php';
if (npp == np) {
$('#test').html(url);
$.ajax({
type: 'POST',
url: url,
data: 'pass=true&'+data,
success: function(data){
$('#pass-form').slideUp(800);
$('.pass-true').fadeIn(800);
},
error: function(){
$('.pass-false').fadeIn(800);
}
});
}
else {
$('.pass-check').fadeIn(800);
}
});