-1

I am using retrofit2. I want to make a post method. English is stored properly, but when I try to store Hindi/Bengali It doesn't show the real data in the database.

ID - 4 and 5 were created from a SQL command.
ID - 6 was stored by POST method from Android.
ID - 7 was stored by the same method but it didn't have any problem.

This is the picture of database

Below the code is for server side API

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);


if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $text = $_POST['text'];
    $options = $_POST['options'];

    $query = "INSERT INTO questions (text, options) VALUES ('$text', '$options')";
    if ($conn->query($query) === TRUE) {
        echo "Question added successfully";
    } else {
        echo "Error: " . $query . "<br>" . $conn->error;
    }
}

$conn->close();
?>

This is my android API Interface:

import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

public interface ApiService {
    @FormUrlEncoded
    @POST("add_question.php")
    Call<Void> addQuestion(
            @Field("text") String text,
            @Field("options") String options
    );
}

Help me solve the problem and write me the solution code if it is needed. I just need the word what I input in my edittext and want to see it in my phpmyadmin exactly like that...

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Aug 16 '23 at 13:54

0 Answers0