dongzanghua8422 2017-11-06 01:14
浏览 153

插入数据库utf-8编码

I get some data in java from http and then I want insert all data in one query to my database using java and php script but i have error:

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 '??okietka', '247335'), at line 1

What is interesting when i copy text from http and add manualy it works, but when i get data from url and then my program put this data i have this error. I think it is a coding problem. my insert php file :

   <?php
require "connection.php";
header('Content-Type: text/html; charset=utf-8');
ini_set('default_charset', 'UTF-8');

$table_name = $_POST["table_name"];
$rows_name = $_POST["rows_name"];


$values = $_POST["values"];
mysqli_set_charset($connection,'utf8');

$mysql_query = "insert ignore into $table_name $rows_name values $values";
if(mysqli_query($connection,$mysql_query) == TRUE){
    echo "Insert Succesful" ;
}
else{
    echo "Error: " . $mysql_query . "<br>" . $connection->error;
}
mysqli_close($connection);
?>

Other data from http I successfully inserted.

Edit: I think i solved this problem adding this to php:

 header('Content-Type: text/html; charset=utf-8');
ini_set('default_charset', 'UTF-8');
mysqli_set_charset($connection,'utf8');
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?