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

时间:2013-08-20 19:43:57

标签: php mysql post utf-8

我有以下问题...我正在构建一个Android应用程序,我使用POST方法从editTexts格式化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在希腊语中显示和添加其他数据。

1 个答案:

答案 0 :(得分:0)

最后我发现了我的问题的解决方案,我使用GET方法而不是POST,现在它正常工作!对于sql注入技巧的thnx,我会详细了解这个问题!