I'm trying to perform an Ajax POST request and the result is returned from PHP by echo. I've just noticed that the result is returning two additional unknown characters.
This is my JavaScript:
$.ajax({
type: "POST",
url: "php/login.php",
data: loginDataString,
cache: false,
success: function(result){
alert(result);
swal("Incorrect", result, "error");
}
});
And my whole 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";
}
?>
And the result here

