Andreas Konstantakos Andreas Konstantakos - 7 months ago 19
PHP Question

Response method doesnt working properly in php script

I make a project in android studio for login/register.
I use volley library and a php script that connects my java code with my database.The POST method working perfectly and i can insert information in my database.But i get nothing on response.Seems there is an error in my php script.
Here is the php script:

$con = mysqli_connect("mysql10.000webhost.com", "a3288368_user", "abcd1234", "a3288368_data");

$name = $_POST["name"];
$age = $_POST["age"];
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, age, username, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $age, $username, $password);
mysqli_stmt_execute($statement);

$response = array();
$response["success"] = true;

echo json_encode($response);


Any ideas what is going wrong?

Answer

Use

print_r(json_encode($response));

You can't echo json string.

Comments