1

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\"?>\n"; // XML header
$xml_output .= "<answers>\n";

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

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

$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_

0

4 Answers 4

1

urldecode will do the job.

On the side note, it is very bad practice to send queries like that. Send the necessary data, filter it and then construct the query, unless you're building a clone of phpMyAdmin.

Sign up to request clarification or add additional context in comments.

2 Comments

In my case it's easier because I address different queries to the same php file from one as3 class.
But I can understand why it is very bad practice.
0

flash may be requesting the url with encoded parameter/querystring so decode it in php using urlencode.

i.e

$Q = urldecode($_GET['Query']);

2 Comments

The problem when I do it this way, is that my DATA base field message is empty! Data has been sent to the DB but the field is empty...
it may be problem with ur database... is it accepting utf8chars? is the message length within its range?
0

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_

2 Comments

$Q = mysql_real_escape_string($_POST['Query']);. "solved"!.
Yeah better like this! Thank you Colonel.
0

$q = mysql_real_escape_string(urldecode($_GET['Query']));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.