撇号或符号导致MySQL错误

时间:2019-05-23 06:17:59

标签: php mysql json unicode

当我尝试将以下数据输入数据库时​​,这些字符会产生问题:ContactPanel&)和\u0026'

\u0027

PHP代码:

{  
    "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.",
}

错误:

<?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!!!";
     }
?> 

1 个答案:

答案 0 :(得分:0)

请勿使用以下格式:\u0026

不要对放入INSERT(和其他SQL语句)中的任何字符串使用“绑定”或以其他方式转义。