PDA

View Full Version : Php and as3 variable help


johnreal
09-04-2011, 12:05 AM
Ok i am new to php and a few months into as3, i decided to test out php and as3, so i want to make a simple log on system with php, as3, and a few text file no MySQL or anything.
There are 3 text file set with some info in it like the user name, i want the user to type in a name that is set in the file already, and then a password, and the password is set as the new password for the account.
Everything works good except, i don't know how to tell the php which text file to look for, here is part of my code this part creates part of the account,

Here is my code:
AS3 :cool:
//create account with password
//create is a button that is pressed to set the password
create.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler2);

function fl_MouseClickHandler2(event:MouseEvent):void
{
function sendData():void {
variables = new URLVariables();
fData = new URLRequest("fSubmit2.php");
fData.method = URLRequestMethod.POST;
fData.data = variables;

fLoader = new URLLoader();
fLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
fLoader.addEventListener(Event.COMPLETE, sendComplete);

//alldata is the data that already exists in the text file
var myTextLoader:URLLoader = new URLLoader();
variables.TheText=alldata.text+'&mypasscode='+mypassword.text;
fLoader.load(fData);
}

function sendComplete(e:Event):void {
var loader:URLLoader = new URLLoader();
//username was typed in previously and the text file is the user name so i //type john as my name and there is a file named john.txt
loader.load(new URLRequest(username.text+".txt"));
}

sendData()
gotoAndStop(2);
}
}

Ok thats the as3, its only piece please say if i didnt explain something right thanks
Now ,here is my problem the php :confused:
<?php

$getVar = $_POST[TheText];

$file = username+'.txt';

$writeVar = fopen($file,'w');

fwrite($writeVar,$getVar);

fclose($writeVar);

?>

It works perfectly except $file = username'.txt'; i can put
$file = 'john.txt'; but it would only access the john file i want it to access the file based on the name i type, please say if i am not clear, thanks in advance.

notaflasher
09-13-2011, 05:28 AM
John, there might be something else going on, but I'm curious about the "+" in the line you are having problems with.

Php doesn't recognize "+" as actionscript does. If you want to combine strings in php, use a dot.

$file = username.".txt";

And try substituting double quotes for singles unless you have sets of quotes nested inside another. I'm not saying that your single quotes are wrong, just that I have solved problems in the past by substituting one for the other when things weren't working as expected. I hope this helps.

And if henke37 shows up and gives you some grandiose explanation that makes him sound very intelligent, but doesn't help you in the slightest, join the crowd.