im working on an app which the users needs to login to. This is coded in Java, the login works without problems. However, i want to receive the "message" from the json and display it. As i said, the code works, but only if the json string "message" dosent contain any special characters like æ, ø, å. I've tried anything, also, i have another file which gets the data from the DB and shows it in a listview, used the exact same code, and this works. The json in the login.php returns NULL, it replaces the whole string and just replaces it with NULL.
My login.php (returning null)
<?php
header('content-type:text/json;charset=utf-8');
$Uname = $_POST["txtUName"];
$Pass = $_POST["txtPass"];
$con=mysqli_connect("localhost","user","pass","db");// Check connection
if (mysqli_connect_errno())
{
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET NAMES 'utf8'");
$result = mysqli_query($con,"SELECT * FROM users where email='$Uname' AND encrypted_password='$Pass'");
while($row = mysqli_fetch_array($result))
{
$response["success"] = 1;
$response["message"] = $row['firstname'] . " " . $row['lastname'];
die(json_encode($response));
//header("Location: home.php");
}
mysqli_close($con);
?>
My getdata.php (works)
<?php
include "db_config.php";
$cat = $_GET['app_category'];
if($cat == '99'){
mysql_query("SET NAMES 'utf8'");
$sql=mysql_query("SELECT * FROM `test_fc`");
while($row=mysql_fetch_assoc($sql)) $output[]=$row;
print ('{ "app_item":');
print(json_encode($output));
print ('}');
mysql_close();
} else {
mysql_query("SET NAMES 'utf8'");
$sql=mysql_query("SELECT * FROM `test_fc` WHERE app_category={$cat}");
while($row=mysql_fetch_assoc($sql)) $output[]=$row;
print ('{ "app_item":');
print(json_encode($output));
print ('}');
mysql_close();
}
?>
My java parser can read the getdata.php without any problem, even with special characters.
I've been stuck on this for the past couple of days. Any help is much appreciated!
EDIT: Getting {"message":null,"success":}