duanchuaiwan0063 2010-05-30 07:55
浏览 17
已采纳

As3&PHP URLEncoding问题!

I'm stuck with a stupid problem of encoding.

My problem is that all my accentuated characters are displayed as weird iso characters.

Example : é is displayed %E9

I send a string to my php file :

XMLLoader.load(new URLRequest(online+"/query.php?Query=" + q));
XMLLoader.addEventListener(Event.COMPLETE,XMLLoaded);

When I trace q, I get :

"INSERT INTO hello_world (message) values('éàaà');"

The GOOD query

My php file look like this :

<?php 

include("conection.php");//Conectiong to database

$Q = $_GET['Query'];

$query = $Q;
$resultID = mysql_query($query) or die("Could not execute or probably SQL statement malformed (error): ". mysql_error());

$xml_output = "<?xml version=\"1.0\"?>
"; // XML header
$xml_output .= "<answers>
";

$xml_output .= "<lastID id=".'"'.mysql_insert_id().'"'." />
";

$xml_output .= "<query string=".'"'.$query.'"'." />
";

$xml_output .= "</answers>";

echo $xml_output;//Output the XML

?>

When I get back my XML into flash the $query looks like this :

"INSERT INTO hello_world (message) values('%E9%E0a%E0');"

And these values are then displayed into my DB which is annoying.

Any help would be appreciated! Cheers.

Jk_

  • 写回答

4条回答 默认 最新

  • dshnx48866 2010-05-30 09:39
    关注

    My problem is now solved!

    As andr wrote down above, it's really a bad idea to use GET to send a queries.

    It seems that when I sent the data from Flash using :

    XMLLoader.load(new URLRequest(online+"/query.php?Query=" + q));
    

    the URL was encoded and even with urldecode I got a blank entry in my DB.

    So thanks to andr and raz-l I changed the way I send the data to my php file.

    In flash I use URLVariables and in PHP I build my query:

    variables = new URLVariables();
    variables.Query = "éàûï ceci est un test...";
    request.method = URLRequestMethod.POST;         
    request.data = variables;
    XMLLoader.load(request);
    

    And my php file looks like this :

    $Q = mysql_real_escape_string($_POST['Query']);
    $query = "INSERT INTO hello_world (message) values ('".$Q."')";
    

    Jk_

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示