Home>

There is a json file that is sent to the database via a php script and written to one of the cells. I get the same error from time to time:

[Mon Feb 14 02:38:00.632563 2022] [php:error] [pid 8316:tid 12364] [client *****] PHP Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\xd0\xba\xd0\xb5\xd0\xb9, \xd1\x81\xd0\xba\xd0\xb0\xd0\xb6\xd1\ x83 \xd0\xbd\xd0\xb0 \xd0\xb1\xd0\xbe\xd0\xbb\xd0\xb5\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xbd\xd1\x8f\xd1\x82\ xd0\xbd\xd0\xbe\xd0\xbc \xd1\x82\xd0\xb5\xd0\xb1\xd0\xb5 \xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba\xd0\xb5, \xd0 \xbf\xd1\x80\xd0\xb8\xd1' at line 1 in C:\Apache24\htdocs\Loc\Php\VstavitJson.php:14\nStack trace:\n#0 C:\Apache24\htdocs\Loc\ Php\VstavitJson.php(14): mysqli_query(Object(mysqli), 'UPDATE LeagueOf...')\n#1 {main}\n thrown in C:\Apache24\htdocs\Loc\Php\VstavitJson.php on line 14

Russian letters may appear in the json file itself. It seems that the error swears at them, but I do not understand how to fix it. Does anyone have any ideas?

VstavitJson.php code:

<?php
include('ConfigLoD.php');
if (isset($_POST))
{
    $id= $_POST['id'];
    $histjson=$_POST['histjson'];
$sql= "UPDATE LeagueOfDreamers SET histjson= '$histjson' WHERE id= '$id' ";
if (mysqli_query($db, $sql))
 {
   echo "histjson updated successfully";
}
else
{
   echo "Error updating record Json: " . mysqli_error($db);
}
}
?>

before inserting data into the database, the data itself must be escaped.

Andrey Mihalev2022-02-14 02:14:40

Check the encoding in which you send json to the server and the database encoding.

phpBear2022-02-14 03:07:20

Check the CHARSET of the server, client, connection... add the required SET NAMES to the additional connection commands.

Akina2022-02-14 04:31:28