php - _POST 方法返回 ???当请求utf8字符时

标签 php mysql post utf-8

我有以下问题...我正在构建一个 Android 应用程序,并且我使用 POST 方法从 editTexts regeuest 格式化为 utf8(希腊字符)的文本。 POST 方法从 editTexts 中获取希腊语 chras 作为“???”并将它们再次插入到 mysal 中作为“???” POST 将如何识别我的希腊字符???

<?php
// PHP variable to store the host address
 $db_host  = "localhost";
 // PHP variable to store the username
 $db_uid  = "lolen";
 // PHP variable to store the password
 $db_pass = "lolen";
 // PHP variable to store the Database name  
 $db_name  = "lolen"; 
        // PHP variable to store the result of the PHP function 'mysql_connect()' which establishes the PHP & MySQL connection  
 $db_con = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');

   mysql_query("SET character_set_results=utf8", $db_con);
    mb_language('uni'); 
    mb_internal_encoding('UTF-8');
    mysql_select_db($db_name, $db_con);
    mysql_query("set names 'utf8'",$db_con);

// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['k_p']) ) 
{
$Kwdikos_Proiontos=$_POST['k_p'];
$Proion=$_POST['p'];
$Kwdikos_Tupou=$_POST['k_t'];
//$Tupos=$_POST['t'];
$sql=mysql_query("SELECT * FROM tupoi WHERE Kwdikos_Tupou LIKE '". $_POST["k_t"]."'", $db_con);
while($row = mysql_fetch_array($sql))
  {
$output[]=$row['Tupos'];
$re= json_encode($output[0]);
$dd= json_decode($re, true);
  }
$result =mysql_query("INSERT INTO proionta(Kwdikos_Proiontos, Proion, Kwdikos_Tupou, Tupos) VALUES('$Kwdikos_Proiontos', '$Proion', '$Kwdikos_Tupou', '$dd')");
 //check if row inserted or not
    if ($result) {
        // successfully inserted into database
       $response["success"] = 1;
        $response["message"] = "Product successfully created.";

        // echoing JSON response
        echo json_encode($response);
    } 
    else    {
        // failed to insert row     
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";

        // echoing JSON response
       echo json_encode($response);
    }
}
 else 
{
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>

ps。我的数据库已经采用 utf8 格式,因为我通过在数据库中使用 SELECT 、 INSERT 以希腊语显示和添加其他数据。

最佳答案

终于我找到了解决问题的方法,我使用了 GET 方法而不是 POST,现在它可以正常工作了!感谢 SQL 注入(inject)提示,我将阅读有关此问题的更多信息!

关于php - _POST 方法返回 ???当请求utf8字符时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18343734/

相关文章:

php - 使用 SHA1 时如何检查 PHP 字段是否为空

php - 使用 php 运行 cron 作业时出现错误,我该如何解决?

MySql查询获取只有一个连接行的行

ajax - firebug 网络监视器选项

php - 管理注册网站 Cron 作业的最佳方式

mysql - phpmyadmin - sql 查询错误

mysql - 170 MB 的数据库对于 350 个帖子来说是否太大?

JQuery AJAX 语法

php - 当 $_GET 是我唯一的选择时发送用户名 + 密码的最安全方式

php - mb_detect_encoding 不能在 Windows-1250 (CP1250) 上正常工作