Locked

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

New Here ,
Apr 01, 2018 Apr 01, 2018

Copy link to clipboard

Copied

i get Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

can anyone help me please

this my as3 flash code

package communication2 {

   

    import flash.display.MovieClip;

    import flash.display.Sprite;

    import flash.events.*;

    import flash.text.TextField;

    import flash.net.navigateToURL;

    import fl.data.DataProvider;

    import flash.net.URLVariables;

    import flash.net.URLRequest;

    import flash.net.URLRequestMethod;

    import flash.net.URLLoader;

    import flash.net.URLLoaderDataFormat;

    import flash.events.IOErrorEvent;

    public class Communication2 extends MovieClip {

private var myRequest:URLRequest;

private var myVars:URLVariables;

private var myLoader:URLLoader;

        public function Communication2() {

myVars = new URLVariables();

myRequest = new URLRequest();

myRequest.url="http://localhost/login/communication2.php";

myRequest.method=URLRequestMethod.POST;

myRequest.data=myVars;

myLoader = new URLLoader();

myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

myLoader.addEventListener(Event.COMPLETE, showGrid);

myLoader.addEventListener(IOErrorEvent.IO_ERROR, showError);

getData();

mySubmit.addEventListener(MouseEvent.CLICK, submitData);

}

function submitData(e:MouseEvent) {

if (firstName.text == "" || lastName.text == "" || fear.text == "") {

navigateToURL(new URLRequest("javascript:alert('Please enter all fields');"), "_self");

} else {

getData(firstName.text, lastName.text, fear.text);

firstName.text = lastName.text = fear.text = "";

}

}

function getData(myFirstName:String="", myLastName:String="", myFear:String="") {

myVars.firstName = myFirstName;

myVars.lastName = myLastName;

myVars.fear = myFear;

myLoader.load(myRequest);

}

private function showGrid(e:Event) {

var newVars:URLVariables = new URLVariables(e.target.data);

trace (newVars.simpleVariable);

if (newVars.error == 0) {

var myDataProvider:Array = [];

for (var i:uint=1; i<=newVars.total; i++) {

myDataProvider.push({firstName:newVars["firstName"+i], lastName:newVars["lastName"+i], fear:newVars["fear"+i]});

}

myGrid.columns = ["firstName", "lastName", "fear"];

myGrid.dataProvider = new DataProvider(myDataProvider);

myGrid.getColumnAt(0).headerText = "First Name";

myGrid.getColumnAt(0).width = 100;

myGrid.getColumnAt(1).headerText = "Last Name";

myGrid.getColumnAt(1).width = 100;

myGrid.getColumnAt(2).headerText = "Greatest Fear";

} else {

trace("There was an error in PHP");

}

}

        private function showError(e:IOErrorEvent) {

            trace("There was an error!");

        }

       

    }

   

}

and the php code

<?php

$firstName = isset($_POST['firstName']) ? $_POST['firstName'] : "";

$lastName = isset($_POST['lastName']) ? $_POST['lastName'] : "";

$fear = isset($_POST['fear']) ? $_POST['fear'] : "";

$date = date("Y-m-d");

$error = 0;

$db = mysql_connect("localhost", "username", "password");

mysql_select_db("database",$db);

if ($firstName != "") {

$query = "INSERT INTO fears (id, firstName, lastName, fear, date) VALUES ('', '$firstName', '$lastName', '$fear', '$date')";

$result = mysql_query($query,$db);

if (!$result) {

$error = "Sorry could not record fear";

}

}

echo "simpleVariable=simple value";

$query = "SELECT * FROM fears";

$result = mysql_query($query,$db);

$total = mysql_num_rows($result);

$output = "";

if ($result) {

$i=0;

while ($myrow = mysql_fetch_array($result)) {

$i++;

$output .= "&firstName".$i."=".urlencode($myrow['firstName']).

   "&lastName".$i."=".urlencode($myrow['lastName']).

   "&fear".$i."=".urlencode($myrow['fear']);

}

} else {

$error = "Sorry could not access fears";

}

echo "&total=".urlencode($total)."&error=".urlencode($error).$output;

?>

Views

295

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 01, 2018 Apr 01, 2018

Copy link to clipboard

Copied

try to remove myLoader.dataFormat = URLLoaderDataFormat.VARIABLES

or trace (e.target.data) and see if there are no strange chars

from var newVars:URLVariables = new URLVariables(e.target.data);

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

what do you mean strange chars?give me example beacause i'm new with flash
i try remove

myLoader.dataFormat = URLLoaderDataFormat.VARIABLES

or trace (e.target.data)

but still get error

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

paste the result of trace(e.target.data)

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

i dont understand..can you type the full code that you mean??

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

in showGrid(e:event)

paste the result of trace(e.target.data)

to see the shape of your PHP script result

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines