Good day!
In the database "cars", in the table "marki" there is a field "json".
I inserted the name of the stamps into it via json_encode.
Now you also need to insert brand names through "htmlspecialchars".
To also displayed!
But inserts an empty string. How to fix the code?

My code is:

$marka=@$_POST['marka_name']; $far=array('marka_name'=>$marka); $json1=htmlspecialchars($far); $sql="INSERT INTO marki (json)value('$json1')"; $res = mysqli_query($connect,$sql); if($res){ echo "<script>window.location='index.php'</script>"; } 

?> enter image description here

    2 answers 2

    Everything turned out to be just! Input to the database is:

     if($target=="add_marka"){ $marka=@$_POST['marka_name']; $far=array('marka_name'=>$marka); // normJsonStr - функция руссификации для PHP ранее 5.4 $json=normJsonStr(json_encode($far)); $json1=htmlspecialchars($json); $sql="INSERT INTO marki (json)value('$json1')"; $res = mysqli_query($connect,$sql); if($res){ echo "<script>window.location='index.php'</script>";} } } 

    The output to the browser will be the opposite: first htmlspecialchars_decode , and then json_decode ! I hope this code will help colleagues!

      If you still use mysqli (which is correct), then you need to do so to create the request

       $db=new mysqli(...); $sql="INSERT INTO marki (json)value(?)"; $stmt=$db->prepare($sql); $stmt->bind_param('s',$json1); $stmt->execute();