-2

When I try to enter the following data into the database, these characters create problems: & (\u0026) and ' (\u0027)

{  
    "Id":5507542,"Name":"Port \u0026 Company® - Youth 50/50 Cotton/Poly T-Shirt",
    "Description":"Cover you kids in the best threads by Port \u0026 Company®. This youth T-shirt is something they\u0027ll always run back to! It\u0027s made of 5.5 oz., 50% cotton / 50% poly (with up to 5% recycled polyester from plastic bottles). 
    They\u0027ll stay visible in the Safety Green and Safety Orange colors because they\u0027re compliant with ANSI/ISEA 107 high visibility standards for background color. Imprint your company name to this top and let the clients come to you!",
    "ShortDescription":"50/50% Cotton/Poly T-Shirt.",
}

The PHP code:

<?php


    $host="localhost";

    $user="root";

    $password="";

    $db="db";


     $connect =  mysqli_connect($host,$user,$password,$db) or die('Database Not Connected. Please Fix the Issue! ' . mysqli_error());


     $id = $content['Id'];  

     $name = $content['Name'];

     $description = $content['Description'];

     $shortDescription = $content['ShortDescription'];


    $query = "INSERT INTO result_tab(id,name,description, shortDescription) VALUES('$id', '$name', '$description', '$shortDescription')";

     if(!mysqli_query($connect,$query))
    {
        die('Error : Query Not Executed. Please Fix the Issue!  ' . mysqli_error($connect));
    }
     else{
            echo "Data Inserted Successully!!!";
     }
?> 

The error:

Query Not Executed. Please Fix the Issue! You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near 'll always run back to! It's made of 5.5 oz., 50% cotton / 50% poly (with up to 5' at line 1
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263

1 Answers1

0

Don't use this format: \u0026.

Do use "binding", or otherwise escaping, any string put into INSERT (and other SQL statements).

Rick James
  • 135,179
  • 13
  • 127
  • 222