-
Senior Member
[RESOLVED] url name/value pair problem
I recently made a contact form and that was working well without any problems. The url was called in this way:
var request:URLRequest = new URLRequest();
request.url = "mailform.php";
Now I was creating a component, where I want to pull out something from a database using a php file. The php file was originally defined by a setter/getter method. However, even i add the actual url like here:
var request:URLRequest = new URLRequest();
request.url = "getdata.php";
I end up getting a 2101 error;
Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
Usually from what I saw the error is thrown when certain characters ampersand etc are used incorrectly, but this is not the case here.
Anybody any other ideas? Also why in one case it works fine but not in another case.
Thanks
- The right of the People to create Flash movies shall not be infringed. -
-
Based on that error, it seems that the data requested from getdata.php is not in an expected format for URLVariables.decode() to distinguish. See Working with External Data Flash CS3
Under the heading Loading data from external documents you will see an example of retrieving data that is formatted in name-value pairs.
You can either parse it using a URLVariables object or using the URLLoader.dataFormat property to the appropriate type (BINARY, TEXT, or VARIABLES) The default value for URLLoader.dataFormat is URLLoaderDataFormat.TEXT. Trace the retrieved data to make sure what format its in.. I hope this helps and I hope it works out for you. Let us know
-
Senior Member
Thanks for your help, but the Adobe site is not really helpful in the prtoblem I have.
I don't get it. This is what I have in my script, which is just regular sending variables:
var variables:URLVariables = new URLVariables();
variables.myTable = mySearchTable;
variables.searchItem = myClip.keyWsearch.searchWindow.text;
var request:URLRequest = new URLRequest();
request.url = "getdata.php";
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener (Event.COMPLETE, completeHandler);
The problem must be the php script, because I have created with this mail scripts without any problems.
Here is the last part from the php script. That must be the part where I have a problem (I guess?).
$newResult = substr_count(strtolower($subitem1),strtolower($sea rchItem));
if($newResult >= 1)
{
$matchCounter = $matchCounter + 1;
$xmlNodes .= "<item id=\"$id\" name=\"$name\" age=\"$age\" myUrl=\"$myUrl\" htmlUrl=\"$htmlUrl\" pic=\"$pic\"><p><h1>$name</h1><ul><li>age: $age</li><li>hair color: $haircolor</li><li>phone: $phone</li></ul></p></item>";
}
echo "&myResult=" . urlencode($xmlNodes);
echo "&countResult=$matchCounter";
}
}
else
{
fail("ERROR: There are no data.");
}
//general function in case of errors
function fail($errorMsg)
{
echo "&myResult=" . urlencode($errorMsg);
exit;
}
//we close the connection to the database
mysql_close($link);
exit;
?>
- The right of the People to create Flash movies shall not be infringed. -
-
Senior Member
Ok,
I am getting closer. The php part has to be like this:
"Var1$theResult=Var2$matchCounter&Var3$myResul t=" . urlencode($xmlNodes)"&";
echo "theResult=$theResult";
and the Flash site like this
loader.dataFormat = URLLoaderDataFormat.TEXT;
At least that gives me a response in the completeHandler function. I will come back if I still have problems.
- The right of the People to create Flash movies shall not be infringed. -
-
Senior Member
Ok,
the problem is that Flash does not recognize any of the variables from php.
I have this:
echo "&countResult$theResult=$matchCounter&myResult$the Result=" . urlencode($xmlNodes);
When I ask for event.target.data.countResult it does not see the variable. Any ideas are as usual appreciated.
- The right of the People to create Flash movies shall not be infringed. -
-
Senior Member
Ok,
I moved on. I forgot to enter the correct table names(), but still it is not yet completely working. If you look at the movie.
http://flashscript.biz/test/search_e..._Datagrid.html
Click on one of the radiobuttons (age under 30) and then select a keyword. I am displaying in a textfield the xml data coming back. That seems to work. But the number of matches, which has a different variable is also shown using the same variable for the xml data, while when I ask for the value it gives undefined (undefined matches found).
This is what I have in the php file. The variables should not have any ampersand. That was one problem.
PHP Code:
color: $haircolor</li><li>phone: $phone</li></ul></p></item>";
}
"myResult=" . urlencode($xmlNodes);
}
echo "myResult$theResult=" . urlencode($xmlNodes);
echo "matchCounter$theResult=$matchCounter";
This is what I have inside the completehandler function:
PHP Code:
mySearchEngine.myMessage.text = event.target.data.matchCounter + " matches found!";
pXml = new XMLDocument ("<items>" + event.target.data.myResult + "</items>");
pXml.ignoreWhite = true;
storeData (pXml.firstChild);
private function storeData (searchText:XMLNode):void
{
mySearchEngine.myField.textValue = searchText;
"myField" is the textfield you see, which currently shows the data in the movie. The matchcounter value at the end of the xml should not be there of course.
Any further ideas?
The dataformat has to be VARIABLES. And of course locally it will always give the 2101 error.
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
Last edited by cancerinform; 07-08-2007 at 10:53 AM.
- The right of the People to create Flash movies shall not be infringed. -
-
Senior Member
Resolved, only one echo allowed:
echo "matchCounter=$matchCounter&myResult=" . urlencode($xmlNodes);
}
- The right of the People to create Flash movies shall not be infringed. -
-
Well its great to see that you got it working. I haven't been on for a while and just came in to see how everyone is doing. Thank you for posting your progress. It was a learning experience for me, as I am not very familiar with php. Sorry I could not help out more.
-
Senior Member
I had always the feeling when I answered I talked to someone
- The right of the People to create Flash movies shall not be infringed. -
-
hippie hater
You are, this will be the solution for many things on the future
Last edited by Cimmerian; 07-10-2007 at 07:08 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|