dongxiandi8313 2019-02-02 16:41 采纳率: 100%
浏览 36

从php向表中插入行时如何修复MySQLi数据库

I'm setting up a new web application, and i want to find out a way to insert a row from PHP in Greek language

I make the connection with MySQLi from PHP like this:

 $con = mysqli_connect("localhost", "root", "", "Mydb");  
    if (!$con)    {                                                   
    echo "Error: Unable to connect to MySQL.";
    exit;         }
    if($con){       echo "connected with db <br/>";     } 

next step is to enter some values to a table like this:

    if(isset($_POST['ok']))
    {   
        mysqli_query($con,"INSERT INTO products (product_name,product_delivery) VALUES ('$product_name','$delivey')");                                 
    }   }

if i names of values is in English it works perfectly. But if I'm trying to insert a value in Greek language,then the line of the Data Base table corresponding to this record shows me symbols

Sample picture of the error

  • 写回答

2条回答 默认 最新

  • dop82210 2019-02-02 16:47
    关注

    try the following:

    after you connect to the mysql, do this query to make sure that you are using UTF8:

        mysqli_query("SET NAMES 'utf8'");
        mysqli_query("SET CHARACTER SET 'utf8'");
    

    if this does not help, try different encoding, like ISO-8859-1

    评论

报告相同问题?