MySql,Php未设置为UTF8

I'm inserting utf-8 data to the database with this code

$conn = new mysqli($hostname, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

mysqli_set_charset($conn,"utf8");

$sql = "INSERT INTO Movies (Name, Year)
        VALUES ('".$_POST["name"]."', '".$_POST["year"]."')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

But the data is added like this:

Image

What should I do?

This is something I think you must fix in the back end, the PHP code is perfect, but you need to configure your database to utf-8 as well. You appear to be using PHPmyAdmin, when you create or import the table, you should see a drop down box to select the file's character set. Change this and you should be good to go!

You can use alter command in mysql to change all the fields to utf8 format,

Please check the sql query

ALTER TABLE `Movies` CHANGE `Name` `Name` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;

That should start (end?) with Arabic 'noon' (ن), correct?

&#1606; is the "html entity" for 'noon'.

Was the user filling in an html <form>? does it include a charset, such as <form accept-charset="UTF-8">? If not, that might be the solution.

Is the column/table declared CHARACTER SET utf8 (or utf8mb4, but not utf32)? It needs to be. See SHOW CREATE TABLE.