Regarding using flash to post data to php script

Hi all,

Regarding this topic

I am having an issue with a flash and php script my flash file isnt submitting the changes to my php script located at my site demo.willbc.com/joomla/update.php

i get no errors
this is my php code


$name=$_POST['username'];
$cp=$_POST['cexp'];
$mp=$_POST['mexp'];
$hpy=$_POST['happy'];
$e=$_POST['energy'];
$conf=$_POST['confidence'];
$gold=$_POST['money'];
$name=$_POST['username'];
$lastLogin=$_POST['lastLogin'];
$lastConfidenceReplenish=$_POST['lastConfidenceReplenish'];
$lastEnergyReplenish=$_POST['lastEnergyReplenish'];
$curEnergy=$_POST['curEnergy'];
$curConfidence=$_POST['curConfidence'];
$sparePoints=$_POST['sparePoints'];
$foodLog=$_POST['foodLog'];
$achievements=$_POST['achievements'];
$money=$_POST['money'];
$recent=$_POST['recent'];
$activities=$_POST['activities'];
$thoughtList=$_POST['thoughtList'];
$inventoryItems=$_POST['inventoryItems'];
$lastSave=$_POST['lastSave'];
$energy=$_POST['energy'];
//
//
include("dbconnect.php");
	$u="update gg46_users set cexp='$cp',mexp='$mp',energy='$e',happy='$hpy',confidence='$conf',money='$gold'
	,lastvisitDate='$lastLogin',lastConfidenceReplenish='$lastConfidenceReplenish',lastEnergyReplenish='$lastEnergyReplenish',
	curEnergy='$curEnergy',curConfidence='$curConfidence',sparePoints='$sparePoints',foodlog='$foodLog',achievements='$achievements',confidence='
	$confidence',recent='$recent',activities='$activities',thoughtList='$thoughtList',inventoryItems='$inventoryItems',lastSave='$lastSave' WHERE username='$name'";
	//echo $u;
	$rs=mysqli_query($con,$u);
	if(!$rs)
	{
		//
		echo "Somthing Went Wrong".mysqli_error($con);
		//
	}
	else
	{
		echo "Successful Update";	
	}
//

as for flash file this is my flash action script code


public static const WEB_ADDRESS_GET:String = "site.com/site.php";
		public static const WEB_ADDRESS_SEND:String = "site.com/siteget.php";
		private static const LOGGED_USER_REQUEST:int = 1;
		private static const GET_USER_DATA:int = 2;
		private static const SEND_USER_DATA:int = 3;
		private var commStatus:int = 0;		
		private var req:URLRequest = new URLRequest(WEB_ADDRESS_GET);
		private var loader:URLLoader = new URLLoader();
		private var URLvars:URLVariables = new URLVariables();
		private var myParent:Object = null;
		public function Comms():void {

As for the actionscript for response i get this but abit of a delay


public function saveData(dataToSave:Object, _myParent:Object = null):void {
			myParent = _myParent;
			req = new URLRequest(WEB_ADDRESS_SEND);
			req.method = URLRequestMethod.POST;
			URLvars.data = dataToSave;
			//or ----------
			//URLvars = dataToSave;
			//req.data = URLvars;
			req.data = dataToSave;
			loader.addEventListener(Event.COMPLETE, onSaved);
			loader.load(req);
		}
		function onSaved(e:Event):void {
			if (myParent != null) {
				flash(myParent).debug(" data saved...");
			} else {
				trace('data saved...');
			}
		}

What is going on here why is no data being sent to my php file?

How can i get data to be updated everytime when save data is called?

Can anyone help?

Thanks,William

Try putting http:// in front of the URL.

Your PHP file also has very severe SQL injection problems. You are also trusting the input data, but anyone can just issue his or her own forged request.

yea i have done that still not working or passing any information back to the php script this is my actionscript code i have


public static const WEB_ADDRESS_GET:String = "http://demo.willbc.com/joomla/index.php?option=com_content&view=article&id=1&Itemid=21";
		public static const WEB_ADDRESS_SEND:String = "http://demo.willbc.com/joomla/update.php";
		//public static const WEB_ADDRESS_SEND:String = "http://demo.willbc.com/joomla/update.php";
		//public static const WEB_ADDRESS_SEND:String = "http://demo.willbc.com/joomla/update.php?username=" + my_var; + "exp=" + exp;"";
		var myVars:URLRequest = new URLRequest(WEB_ADDRESS_SEND);
		var player;
		var myVar:player=name;
		//public var myVar:playerexp=exp;
		myVars.send(WEB_ADDRESS_SEND,"_parent","POST");
		private static const LOGGED_USER_REQUEST:int = 1;
		private static const GET_USER_DATA:int = 2;
		private static const SEND_USER_DATA:int = 3;
		private var commStatus:int = 0;		
		private var req:URLRequest = new URLRequest(WEB_ADDRESS_GET);
		private var loader:URLLoader = new URLLoader();
		private var URLvars:URLVariables = new URLVariables();
		private var myParent:Object = null;
		public function Comms():void {
		}

the saving part is this


myParent = _myParent;
			req = new URLRequest(WEB_ADDRESS_SEND);
			req.method = URLRequestMethod.POST;
			URLvars.data = dataToSave;
			//or ----------
			//URLvars = dataToSave;
			//req.data = URLvars;
			req.data = dataToSave;
			loader.addEventListener(Event.COMPLETE, onSaved);
			loader.load(req);
		}

What am i actually doing wrong?? how can i fx this?

Thanks,William

If you haven’t done so already put a simple logger in your PHP script, e.g. file_put_contents(‘/path/to/log’, print_r($_POST, TRUE));
That should log the whole data posted to the script.
If the logfile isn’t created (check file permissions!) you can be sure it’s a flash problem.
If so I think you’re better off asking in a flash forum, e.g. here: http://www.sitepoint.com/forums/forumdisplay.php?f=150
This doesn’t seem to be a “general development issue”, more like a “flash issue”.

okay

This is my updated code this time around i have adding in some variables being passed that are hard-coded here is my updated code


public class Comms extends MovieClip {
		public static const WEB_ADDRESS_GET:String = "http://demo.willbc.com/joomla/index.php?option=com_content&view=article&id=1&Itemid=21";
		public static const WEB_ADDRESS_SEND:String = "http://demo.willbc.com/joomla/update.php";
		private static const LOGGED_USER_REQUEST:int = 1;
		private static const GET_USER_DATA:int = 2;
		private static const SEND_USER_DATA:int = 3;
		private var commStatus:int = 0;		
		private var req:URLRequest = new URLRequest(WEB_ADDRESS_GET);
		private var loader:URLLoader = new URLLoader();
		private var URLvars:URLVariables = new URLVariables();
		private var myParent:Object = null;
		public function Comms():void {
		}
		public function getLoggedInUser():String {
			/*commStatus = LOGGED_USER_REQUEST;
			req.method = URLRequestMethod.GET;
			req.data = URLvars;
			init(loader);
			loader.addEventListener(Event.COMPLETE, onUserNameGet);
			loader.load(req);*/
			return "";
		}
		public function saveData(dataToSave:URLVariables, _myParent:Object = null):void {
			myParent = _myParent;
			req = new URLRequest(WEB_ADDRESS_SEND+"?username=admin&confidence=200");
			req.method = URLRequestMethod.POST;
			//URLvars.data = dataToSave;
			//or ----------
			//URLvars = dataToSave;
			//req.data = URLvars;
			req.data = dataToSave;
			loader.addEventListener(Event.COMPLETE, onSaved);
			loader.load(req);
		}
		function onSaved(e:Event):void {
			if (myParent != null) {
				flash(myParent).debug(" data saved...");
			} else {
				trace('data saved...');
			}
		}

Why is nothing being sent to my php script can anyone help me?

Thanks,William

This is updated version of my action script code posting data to my php script


myParent = _myParent;
			req.method = URLRequestMethod.POST;
			req = new URLRequest(WEB_ADDRESS_SEND);
			req.method = URLRequestMethod.POST;
			dataToSave.username = name;
			dataToSave.experience= exp;
			req.data = dataToSave;
			//URLvars.data = dataToSave;
			//or ----------
			//URLvars = dataToSave;
			//req.data = URLvars;
			req.data = dataToSave;
			loader.addEventListener(Event.COMPLETE, onSaved);
			loader.load(req);

Why am i getting this issues still as ive found out my other method isnt supported for POST.

Try attaching event handlers for the other events, as that may provide some clue.