我正在尝试执行Ajax POST请求,结果由echo
从PHP返回。我刚刚注意到结果又返回了两个未知字符。
这是我的JavaScript:
$.ajax({
type: "POST",
url: "php/login.php",
data: loginDataString,
cache: false,
success: function(result){
alert(result);
swal("Incorrect", result, "error");
}
});
我的整个PHP
<?php
$con = mysqli_connect("localhost","root","","EugeneStore");
if(!$con){
die("Connection error: " . mysqli_error());
}
if($_SERVER['REQUEST_METHOD']=='POST'){
$UN = $_POST['login_username'];
$PW = $_POST['login_password'];
date_default_timezone_set('Asia/Manila');
$t=time(); $timeDAY = date('d',$t); $timeMONTH = date('m',$t); $timeYEAR = date('Y',$t); $timeYEAR2 = date('y',$t); $CURRENTDATE = "$timeDAY/$timeMONTH/$timeYEAR"; $a2 = date('H',$t); $a3 = date('i',$t); $ampm = "";
if ($a2 >= 0 && $a2 <= 11){
$ampm = "AM";
}
if ($a2 >= 12 && $a2 <= 23){
$ampm = "PM";
}
if ($a2 == 13){
$a2 = 1;
}
if ($a2 == 14){
$a2 = 2;
}
if ($a2 == 15){
$a2 = 3;
}
if ($a2 == 16){
$a2 = 4;
}
if ($a2 == 17){
$a2 = 5;
}
if ($a2 == 18){
$a2 = 6;
}
if ($a2 == 19){
$a2 = 7;
}
if ($a2 == 20){
$a2 = 8;
}
if ($a2 == 21){
$a2 = 9;
}
if ($a2 == 22){
$a2 = 10;
}
if ($a2 == 23){
$a2 = 11;
}
$CURRENTTIME = "$a2:$a3 $ampm";
$sql = "SELECT * FROM Users WHERE Username='".$UN."' AND Password='".$PW."'";
$result = mysqli_query($con,$sql);
$count = mysqli_num_rows($result);
if($count==1) {
$rows00 = mysqli_fetch_array($result);
if($rows00['UserType'] == "Admin") {
$ADDSYSREC = mysqli_query($con, "INSERT INTO SystemLogs(Username, Date, Time, Information, Type)
VALUES('".$rows00['Username']."', '".$CURRENTDATE."', '".$CURRENTTIME."', '".$rows00['Username']." Logged into the system', 'Admin')");
echo "Login Correct Admin";
}
if($rows00['UserType'] == "Member") {
$ADDSYSREC = mysqli_query($con, "INSERT INTO SystemLogs(Username, Date, Time, Information, Type)
VALUES('".$rows00['Username']."', '".$CURRENTDATE."', '".$CURRENTTIME."', '".$rows00['Username']." Logged into the system', 'Member')");
echo "Login Correct Member";
}
} else {
echo 'Wrong username or password';
}
} else {
echo "Something is wrong with the system. Try again Later";
}
?>
结果在这里