hide side navigation
    5 most recent
    Web Services
    Library's
    Component's
    Applications
    Articles
  Flash button as Flex icon  Flex form by email  Hello Remoting with AS3  AS3 Saving data from Flash  AS3 Loading data into Flash  Fire Effect  Contact form  Dragable buttons  Hello World with openamf  Loading helper classes  Upload with Flash 8  Transitions effects  Snapshot with Flash 8  Hello World Remoting AS2  Flash AS2 Remoting Connector  Saving data from Flash  Loading data into Flash  FlashCom & Remoting login  Cell Renderer API  Editing a table using remoting components  Flash MX2004 web service classes  Browsing a catalog  amfphp Documentation  Hello World Remoting  Online Store with AMFPHP  Flash clients for Web Services  Web Service Walk Though with NuSoap  Popup windows in flash with javascript  Installing Apache/PHP  MoreOver News Feeds  Load Edit Save Text Files via CGI  Save Movie Clip Postion via PHP and MySQL
Current Page (3) << Previous Page | Next Page >>  View Article Example >> 1 | 2 | 3 | 4 | 5

Part II - Setting up the PHP 

The PHP scripts will be better explained by reading the comments in the attached files. Just open up the PHP script with notepad or any other text editor to make changes. 

The first thing we have to do is connect to the database.  You will need to know your database name, account username, and database password. In order to keep this as simple as possible use an include file to list these variables - They will be the same for each one of your scripts.  This is what is contained in the file Include.inc. One thing to note is that often times the $DBhost variable is slightly different then "localhost" - Sometimes it can be "localhost.yourHost.com".

<?
$DBhost = "localhost";
$DBuser = "UserName";
$DBpass = "DatabasePassword";
$DBName = "DatabaseName";
$table = "saveMovie";
?>

You will notice that at the top of each PHP script there is a line of code something like this: include ('Include.inc'); All this does is to include those variables in the script. It's just an easier way of keeping track of everything. 

Next you want to make a connection to the Database: 

mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");

 You can see how the variables in the Include File are used here. I'm only going to go over in detail the SQL query part of each script. The rest you should be able to figure out by reading through the comments in the File. Also note that for simplicity some basic sercurity precautions where left out. These are not necessary but you might want to include them if you have any type of sensitive data.

User Registration

PHP used in the first Registration section

$query = "INSERT INTO $table (Name, Object1, Object2, Object3, Comment) VALUES ('$RegName' , '', '', '', 'Hello')";
$result = mysql_query($query);

 This will create a new entry in the database for a new user.  The only value we have to worry about for now is the Name variable which will be set to the Name entered in the Flash Movie in the text field Named RegName.  All other variables will be set later.  The name column was defined as being unique when we created the mySQL table so there can only be one User with that Name.  If someone else try's to register with that name they will not be able to. The second line of the above code is what actually performs the query.  The only thing that's returned to the Flash movie at this point is a message to the user proclaiming that registration was successful - Or failed if the Name already exists in the database. You can see how this is done in the actual script. 

Flash Actionscript Used in Registration

All that is required in Flash at this point is to have one text Field Named RegName - Then either on a button or Frame command this Code. 

on (release) {
	Status = "Beginning registration Process... Please Hold";
	loadVariablesNum ("Register.php?RegName="+RegName, 0);
}

I have an extra text field named Status - but this is optional.  Notice on the LoadVariablesNum command I specifically pass the variable RegName to the PHP script.  This is not necessary, adding "Post" will do the same thing. It's just sometimes easier to keep track of what's passed to a script in this way. After a user has entered their Name and hit the register button the LoadVariablesNum Command will call the PHP script, pass whatever was entered in the RegName Field to it and execute the statements. 

User Login

PHP used in Login (Login.php)

$query = "SELECT * FROM $table WHERE Name = '$Name'";
$result = mysql_query($query);
$numR = mysql_num_rows($result);
#If the number of rows is not equal to one then it prints out an error statement - Name not in Database. 
	if ($numR == 1) { 
	print "_root.Status=Success Login Complete&_root.CheckLog=1";
	}
	else {
	print "_root.Status=Failure - Your name was not found - Please register"; 
	}

The first 2 lines of this code preforms the query on the database. It selects the record where the Name entered in the Flash movie is equal to a unique name found in the database.  The next line of code (excluding the comment) checks to see if a record was returned. If a record is returned then the Login is a success.  Then it prints out the results back to flash.  I also pass back another variable to tell the movie if the Login was successful. In this case I named it CheckLog.  The movie will keep looping the second and third frame until it successfully tests that the variable CheckLog is not equal to nothing ie it's now equal to 1.

Actionscript used in Flash for Login

on (release) {
	gotoAndPlay(2);
	Status = "Beginning Login Process.. Please Hold";
	loadVariablesNum ("Login.php?Name="+Name, "0");
}

 This is the actionscript on the Login Button.  Initially the movie stops at the first frame of the root of the movie.  After you hit the Login button it goes to frame 2 and continues to Loop until it finds that there is a value for CheckLog.  The Check part looks Like the following.

if (CheckLog ne "") {
gotoAndPlay (4);
}else {
gotoAndPlay(2);
}

That's it.  After a user has successfully Logged in we can Load the variables for the first Time.  At first they won't have any values. So they come to rest at the default location. 

Current Page (3) << Previous Page | Next Page >> 1 | 2 | 3 | 4 | 5