PDA

View Full Version : Passing variables to PHP, getting the URLVariables error!



jarmanje
March 13th, 2009, 04:20 PM
Hi there, I have written up some code following preivous work. And it seems to me like it is correct. but i am getting the below code when i click on my button to run the function!

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()

Please may someone see if they can spot what is going wrong?!
thanks for taking a look!

This is my AS3:


btn_ok.addEventListener(MouseEvent.CLICK, btn_ok_click_handler);

function btn_ok_click_handler(event:MouseEvent):void {


var theVariables:URLVariables = new URLVariables();
theVariables.varEmail = "test@email.com";
theVariables.varMat1 = "mat1";
theVariables.varMat2 = "mat2";
theVariables.varMat3 = "mat3";
theVariables.varMat4 = "mat4";
theVariables.varMat5 = "mat5";
theVariables.varMat6 = "mat6";
theVariables.varMat7 = "mat7";
theVariables.varMat8 = "mat8";
theVariables.varMat9 = "mat9";
theVariables.varMat10 = "mat10";
theVariables.varMat11 = "mat11";
theVariables.varMat12 = "mat12";
theVariables.varMat13 = "mat13";
theVariables.varMat14 = "mat14";
theVariables.varMat15 = "mat15";
theVariables.varMat16 = "mat16";
theVariables.varMat17 = "mat17";
theVariables.varMat18 = "mat18";
theVariables.varMat19 = "mat19";
theVariables.varMat20 = "mat20";
theVariables.varMat21 = "mat21";
theVariables.varMat22 = "mat22";
theVariables.varMat23 = "mat23";
theVariables.varMat24 = "mat24";
theVariables.varMat25 = "mat25";


var theRequest:URLRequest = new URLRequest();
theRequest.url = "createSampleBook.php";
theRequest.method = URLRequestMethod.POST;
theRequest.data = theVariables;

var theLoader:URLLoader = new URLLoader();
theLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
theLoader.addEventListener(Event.COMPLETE, loadCompleteHandler);
theLoader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
theLoader.load(theRequest);

function handleIOError(event:IOErrorEvent):void {
event.target.removeEventListener(IOErrorEvent.IO_E RROR, handleIOError);
}

function loadCompleteHandler(event:Event):void {

MovieClip(root).mcMessage.showMessage(event.target .data.feedback);
MovieClip(root).mcMessage.visible = true;

}
}

This is my file createSampleBook.php


<?php
@require_once('database.php');
@require_once('function.php');

if(isset($_POST['varEmail']) && isset($_POST['varMat1']) && isset($_POST['varMat2']) && isset($_POST['varMat3']) && isset($_POST['varMat4']) && isset($_POST['varMat5']) && isset($_POST['varMat6']) && isset($_POST['varMat7']) && isset($_POST['varMat8']) && isset($_POST['varMat9']) && isset($_POST['varMat10']) && isset($_POST['varMat11']) && isset($_POST['varMat12']) && isset($_POST['varMat13']) && isset($_POST['varMat14']) && isset($_POST['varMat15']) && isset($_POST['varMat16']) && isset($_POST['varMat17']) && isset($_POST['varMat18']) && isset($_POST['varMat19']) && isset($_POST['varMat20']) && isset($_POST['varMat21']) && isset($_POST['varMat22']) && isset($_POST['varMat23']) && isset($_POST['varMat24']) && isset($_POST['varMat25'])) {

$result = createSampleBook($_POST['varEmail'], $_POST['varMat1'], $_POST['varMat2'], $_POST['varMat3'], $_POST['varMat4'], $_POST['varMat5'], $_POST['varMat6'], $_POST['varMat7'], $_POST['varMa8'], $_POST['varMa9'], $_POST['varMat10'], $_POST['varMat11'], $_POST['varMat12'], $_POST['varMat13'], $_POST['varMa14'], $_POST['varMa15'], $_POST['varMat16'], $_POST['varMat17'], $_POST['varMat18'], $_POST['varMat19'], $_POST['varMat20'], $_POST['varMat21'], $_POST['varMat22'], $_POST['varMat23'], $_POST['varMat24'], $_POST['varMat25']);
echo "feedback=".$result;
}
?>

and this is in my function.php


function createSampleBook($email, $mat1, $mat2, $mat3, $mat4, $mat5, $mat6, $mat7, $mat8, $mat9, $mat10, $mat11, $mat12, $mat13, $mat14, $mat15, $mat16, $mat17, $mat18, $mat19, $mat20, $mat21, $mat22, $mat23, $mat24, $mat25) {
$sql = "INSERT INTO samples (email, mat1, mat2, mat3, mat4, mat5, mat6, mat7, mat8, mat9, mat10, mat11, mat12, mat13, mat14, mat15, mat16, mat17, mat18, mat19, mat20, mat21, mat22, mat23, mat24, mat25) VALUES ('".$email."', '".$mat1."', '".$mat2."', '".$mat3."', '".$mat4."', '".$mat5."', '".$mat6."', '".$mat7."', '".$mat8."', '".$mat9."', '".$mat10."', '".$mat11."', '".$mat12."', '".$mat13."', '".$mat14."', '".$mat15."', '".$mat16."', '".$mat17."', '".$mat18."', '".$mat19."', '".$mat20."', '".$mat21."', '".$mat22."', '".$mat23."', '".$mat24."', '".$mat25."', '".$allowEdit."')";
$result = mysql_query($sql)
or die(mysql_error());
$sampleBookID = getLastsampleBookId($email);
return $sampleBookID;

}

function getLastsampleBookId($email) {
$sql = "SELECT `samples_ID` FROM `samples` WHERE `email` = '".$email."' ORDER BY `samples_ID` DESC LIMIT 0 , 1 ";
$result = mysql_query($sql)
or die(mysql_error());
$row = mysql_fetch_array($result);
return $row[0];
}

It's annoying me, because i have put in test data as above and cannot understand why it's pulling up the error?!

Any help is really appreciated!

Krilnon
March 13th, 2009, 06:01 PM
Can you post the string that PHP generates? It looks like that string is the problem. You can get the raw string by changing the constant that you use from URLLoaderDataFormat.

The output should look something like the output from one of Kirupa's old tutorials: http://www.kirupa.com/developer/mx/externaldata.htm


name=Kirupa Chinnathambi&email=blah@blah.com&location=Earth

jarmanje
March 13th, 2009, 09:18 PM
Hi Krilnon,

Thank you so much for your reply.

I've been looking through the link you send me, and it's confusing. i'm very new to working with PHP.

I can't see how the text file is relating to the method I use with my php communication. What is the text file for?

I dont think any php code is generated because the error is instant when running the function

what difference would it make loading the variables from a text file instead of set values from within flash?

Sorry to be so 'newbie'