Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-26-2008, 08:27 AM   #1
Marcello2
Senior Member
 
Join Date: Nov 2007
Posts: 246
Default Send an object to a php script

I have an object

var userArray:Object = new Object;
userArray[1] =(first_name:"john", family_name:"smith",age:25);
userArray[2]=(first_name:"jane", family_name:"brown",age:27);

Is this code correct ?

var userArray : new LoadVars();
userArray.sendAndLoad("users.php",usersRegistered, "POST');

Thank you for your help.
marcello
Marcello2 is offline   Reply With Quote
Old 02-26-2008, 10:36 AM   #2
daveystew
Dave Stewart
 
daveystew's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 749
Default

Nope.
Your object syntax is off:

userArray[1] =(first_name:"john", family_name:"smith",age:25);

should be

userArray[0] ={first_name:"john", family_name:"smith",age:25};

And you need to actually send the object. At the moment you're sending usersRegistered
daveystew is offline   Reply With Quote
Old 02-26-2008, 11:14 AM   #3
Marcello2
Senior Member
 
Join Date: Nov 2007
Posts: 246
Default

I see.
What about


Code:
var userArray:Object = new Object;
userArray[0] =(first_name:"john", family_name:"smith",age:25);
userArray[0]=(first_name:"jane", family_name:"brown",age:27);



var userArray : new LoadVars();
var myLoad: new LoadVars();
myLoad.onLoad=function(success) {
if (success) {
     trace(userArray);
}
else
{
     trace("error");
}




userArray.sendAndLoad("users.php",myLoad, "POST');
Marcello2 is offline   Reply With Quote
Old 02-26-2008, 11:28 AM   #4
daveystew
Dave Stewart
 
daveystew's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 749
Default

Hey Marcello2,

OK - I'm confused by what you're trying to do, as I think you're mixing up your objects and variables.

Are you first sending data to the server, then second receiving a response from the server?
daveystew is offline   Reply With Quote
Old 02-26-2008, 11:37 AM   #5
Marcello2
Senior Member
 
Join Date: Nov 2007
Posts: 246
Default

I am confused too about how to do it.
I want to send a two dimension array named userArray to my script php which will then record the data in mySQL
And then, of course, I want to load these data again in ActionScript.
I have not found a single exemple anywhere.
Marcello2 is offline   Reply With Quote
Old 02-26-2008, 12:29 PM   #6
daveystew
Dave Stewart
 
daveystew's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 749
Default

OK. It's pretty simple.

To start with you need a Flash-native object to set up the data you will want to send.

ActionScript Code:
var userArray:Array = new Array; // you need an array in this case userArray[0] ={first_name:"john", family_name:"smith",age:25}; // you need correct object syntax using {} curly braces userArray[1] ={first_name:"jane", family_name:"brown",age:27};


Then you need to set up 2 objects. One to send your variables to the server, and one to receive the response.

1 - an object to receive whatever your server responds with (probably an XML string "<xml><result>All OK</result></xml>")

ActionScript Code:
// Results will be XML, so we set up an XML object var results:XML = new XML()

2 - The LoadVars class that does the sending and then loading

ActionScript Code:
var lv: LoadVars    = new LoadVars(); // set up the class

The onload handler will do something useful when the send and load has completed (as in Flash has received a response from the server, such as echo "<xml>.... ... </xml>").
ActionScript Code:
lv.onLoad=function(success) { if (success) trace(results); // remember this is an XML object we set up a minute ago else trace("error"); }

Now you want to send the data.
ActionScript Code:
lv.sendAndLoad("add-users.php", results, "POST"); // Send the data to "add-users.php" // load the response into results // do the send using the POST method


It should just do it's thing, assuming that security is all sorted.

Is that clear?

Last edited by daveystew; 02-26-2008 at 02:22 PM.
daveystew is offline   Reply With Quote
Old 02-26-2008, 12:34 PM   #7
daveystew
Dave Stewart
 
daveystew's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 749
Default

Quote:
Originally Posted by Marcello2 View Post
I want to send a two dimension array

userArray[1] =(first_name:"john", family_name:"smith",age:25);
userArray[2]=(first_name:"jane", family_name:"brown",age:27);
This is NOT a 2-dimensional array. It is a 1-dimensional array with 2 elements
daveystew is offline   Reply With Quote
Old 02-26-2008, 12:56 PM   #8
Marcello2
Senior Member
 
Join Date: Nov 2007
Posts: 246
Default

Thanks ever so much, daveystew : this is very clear indeed.
In fact, I am a migrant from Visual basic 6 and I have lost my footing.
I suppose I have to study the arrays a lot more.
I wish I could find a tutorial with a classic array (id, first_name, family-name, age) that illustrates the Full Monty from Flash to php to SQL and back to PHP and Flash.
The difference in syntax between VB6 and ActionScript specialist is really difficult for me (I guess I am not the brightest coder in the block ).
I wish you a happy day. In Paris,it is quite dull and rainy.
marcello
Marcello2 is offline   Reply With Quote
Old 02-26-2008, 01:01 PM   #9
xxneon
MCL -- FTW
 
xxneon's Avatar
 
Join Date: Dec 2006
Location: Amish Country, PA
Posts: 7,583
Send a message via ICQ to xxneon Send a message via AIM to xxneon Send a message via MSN to xxneon Send a message via Skype™ to xxneon
Default

just an FYI.. you can not send an array object as it is to a php script .. you need to have all your values in one long string .. like for each object you will need to have a variable attached to your loadvars object ..

lets say you have your first object in your array.. and you want to send it ..
ActionScript Code:
var userArray:Array = new Array; // you need an array in this case userArray[0] ={first_name:"john", family_name:"smith",age:25}; var sendLv:LoadVars = new LoadVars(); var receiveLv:LoadVars = new LoadVars(); // this might need changed depending on what your php script sends back. receiveLv.onLoad = function(success){     if(success){         trace(this.response);//a variable that you can have your php echo when the data is successfully saved to the database.         //and you can do whatever else you want too..     } } sendLv.record1 = userArray[0].first_name+","+userArray[0].family_name+","+userArray[0].age; sendLv.sendAndLoad("your.php",receiveLv,"POST");

and then in your php you will have a variable passed called record1 .. that you will have to split the string .. so you can get each part of your record that you want to save..
__________________
Always optimizing...
xxneon is online now   Reply With Quote
Old 02-26-2008, 01:08 PM   #10
daveystew
Dave Stewart
 
daveystew's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 749
Default

Arrays in VB are a nightmare from what I remember! All that redim rubbish... achk!
daveystew is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
send variable to php dreimann Server-Side Scripting 3 02-22-2007 04:48 AM
can't get PHP to send mySQL info back to Flash Darkware Server-Side Scripting 12 09-11-2005 04:27 AM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM
show me the php script!... gk26 ActionScript 1.0 (and below) 1 10-27-2003 10:59 AM
Send to PHP then include that PHP holtzy Server-Side Scripting 3 03-06-2003 03:06 PM


All times are GMT. The time now is 07:54 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.