Save the above php login code as EMI.php into the www root folder.
Save the above php login code as EMI.php into the www root folder.
In the EMI.fla file I use frame 8 for “About Us” section 9 and 10 for “Registration” and set the “login” from frame number 11. So give a frame label name “login” in frame number 11 and make two dynamic text field var = user and var = pass for username and password. Take a keyCatcher button and write the script bellow:
KeyCatcher Script:
on (keyPress "<PageDown>") {
/:reason="";
if (user ne "" && Pass ne "") {
userName = user;
Password = Pass;
loadVariables("http://localhost/EMI.php", _root, "POST");
gotoAndPlay("logLoop");
} else {
/:reason = "Required fields are empty.";
}
}
And also place the fscommand2 script on this frame 11 to set the softKeys
Frame Script:
fscommand2("SetSoftkeys", left, right);
continue...
marlopax
Thursday, October 15, 2009
Confirmation of Login from the server:
After sending the userName and Password to the server script, Flash Lite application has to stay in a loop state as a pre-loader to receive the confirmation report from the server so that it will immediately do the action when it received from the server. To make that pre-loader state we need two frames to loop.
In frame 12 take a dynamic text field with a var name “log” and named the frame label “logName”. Write on the text field “Please Wait”. Now, on frame 13 put this script:
Frame 13 Scripts:
if (reason eq "Success") {
gotoAndStop("start");
} else if (reason eq "Failure") {
gotoAndStop("login");
} else if (reason eq "Please Register") {
gotoAndStop("Register");
} else if (reason eq "") {
if (/:countLoad<4) {
/:countLoad++;
log = log add " .";
} else {
/:countLoad = 0;
log = "Please Wait";
}
gotoAndPlay("logLoop");
} else {
gotoAndStop("login");
}
continue...
marlopax
Friday, October 23, 2009
Registration Form in Flash Lite1.1 and PHP MySQL Interaction:
Registering a user is something different from a login section, because you need some more information of your users to store in your database. This information will help you for further communication to the users to sent newsletters, offers, promotions etc. It is also been important for a business to gather detailed information of your users to make your own user’s list so that you can analyze and get the statistics of the business area, level, sector etc. the followings are some of the basic information for registration form.
Information of Users:
• First Name
• Last Name
• Sex
• Age
• Country
• Address
• City
• Zip
• Phone Number
• E-mail
• Create Date
• User Name
Login Information:
• User Name
• Password
You’ll have to figure out what exactly information you need from the users for your business purposes, and then create a new table in the same database to store the information of the users. Here, for this application I’m going to store the (First Name, Last Name, Sex, Age, Country, Email ID and userName) in User Information table.
continue...
marlopax
Tuesday, November 10, 2009
Switching from TXT to PHP
To get into this discussion of registering into your Flash Lite application, we need to know about SQL functions and MySQL database. The basic thing is to insert data into the database and pull the data out into it or to compare it with the user input data etc. However, to do this we need to learn/know about the database structure and the relationship of the database. This is very important that how you construct the database according to your application. In this login registration example, I will discus to construct the database to get better perform of your application on real time. Instead, to keep all the data into one database table it is always better to store data into different table of a database. This will help to organize your application and to get faster performance.
To move further of the registration section, lets change the structure of the “EMI.fla” application. Instead, to loading the “EMI.txt” text file at the beginning of the application, with all the information of the product. Lets switch the loadVariables URL path to a new php file, which checks information whether is coming from a flash application and return the value otherwise echo a warning message to the browser. This is not for a security purposes, but if someone targets the path from a browser, it returns a custom error message. This will also be a faster process to load and check from server and take the application to the right path.
firstLoadEMI.php
Change the loadVariables url path from EMI.txt to “firstLoadEMI.php”. Create a php file into the www folder of that name, and instead of loading all the information of EMI.txt, just load the information to target the flash Playhead to the “login” Frame Label. Alternatively, you can just delete all the data from EMI.txt except the last line of loaded information (&loaded=data&).
It you load the “firstLoadEMI.php” then change the 1st frame loadVariables script to the following script.
Change loadVariables Code are:
whatToDo="EMI";
loadVariables("http://localhost/firstLoadEMI.php", _root,"POST");
Here, I introduce a new variables “whatToDo” with a string value before the loadVariables and post the value to the firstLoadEMI.php file. This “whatToDo” variable will act as a condition checker and allow developers to write all the codes of login, user registration, edit user information etc. into one php file. However, for now I am doing it in separate php file, which will change later on.
firstLoadEMI.php Code:
<?PHP
//This will hide the error message
iini_set('display_errors', 0);
$whatToDo=$_POST["whatToDo"];
if($whatToDo=="EMI"){
echo "&pick=login&whatToDo=login&loaded=firstLoad&feed= firstLoad&";
}else if(!$whatToDo){
echo "<strong>Warning:</strong> Browser Does Not Support.";
}
?>
This simple code will check with the posted value from flash application and return variables information back to the flash. Here, the “else if()” condition is to print on the browser if it run from browser. The “ini_set();” script will stop displaying the actual error occur and echo the “else if()” echo script.
The preloader code of flash application which will check the firstLoadEMI.php and go to the login frame will be as follows:
Preloader Code:
iif (loaded eq feed) {
gotoAndStop(pick);
} else {
if (/:CountLoad<4) {
/:CountLoad++;
loading = loading add " .";
} else {
/:CountLoad = 0;
loading = "Loading";
}
gotoAndPlay(2);
}
This code will wait for the result from firstLoadEMI.php file from the server and jump to the frame which echoed from the php script.
continue...
marlopax
Thursday, November 19, 2009
Reading and loading data from a txt file by php
PHP can open a txt file, read data from it and can write data into the txt file.
Here, I will discus all the issues that need for the EMI application business.
PHP opens a text file by the fopen() function which needs two parameters.
1. The name of the file with extension
2. The mode to open the file
The possibilities of modes are in bellow
Possible values:
• "r" (Read only. Starts at the beginning of the file)
• "r+" (Read/Write. Starts at the beginning of the file)
• "w" (Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist)
• "w+" (Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist)
• "a" (Write only. Opens and writes to the end of the file or creates a new file if it doesn't exist)
• "a+" (Read/Write. Preserves file content by writing to the end of the file)
• "x" (Write only. Creates a new file. Returns FALSE and an error if file already exists)
• "x+" (Read/Write. Creates a new file. Returns FALSE and an error if file already exists)
PHP returns a line of a opened file by fgets() function. The feof() of PHP checks the end-of-file.
Here I am going to discus, how php open a txt file on read mode and return each line until the end of the file.
PHP code:
$file = fopen("EMI.txt","r");
while(!feof($file)){
$data = fgets($file;
echo $data;
}
Place this code in the success condition, so that it returns the product data after a successful login. It is better to put this code above the echo "&reason=Success&"; line because after loading the entire product data flash will receive the “success” value and proceed the pre-loader command.
continue...
marlopax
Saturday, November 28, 2009
Merry Christmas and Happy New Year to all
Let us continue
Now, we can discus how to build our registration form in Flash Lite 1.1 application. As we discus earlier that, for this application we are going to built the registration form with (First Name, Last Name, Sex, Age, Country, Email ID and User Name and Password) information. I used Frame Number 9 for registration form in this application and named the frame label “Register”. In this frame, built input variables text field for the above said information. Name each input text field var as the above-mentioned name. This is not mandatory to name as above (example: for First Name text field you can put “FName” or “FirstName” as var name to distinguish the input field, what will it for).
To submit the request use one of the soft key. I used right soft Key as submit button and labeled “Submit”. I also used a cancel and back to start frame in left soft key labeled “Cancel”.
KeyCatcher Button Script:
on (keyPress "<PageDown>") {
if (FName ne "" && LName ne "" && Age ne "" && Sex ne "" && Country ne "" && Email ne "" && UserName ne "" && Password ne "") {
whatToDo = "Register";
loadVariables("http://localhost/EMI.php", _root, "POST");
gotoAndPlay("logLoop");
}
}
on (keyPress "<PageUp>") {
gotoAndStop("login");
}
continue...
marlopax
Tuesday, January 05, 2010
MySQL, Relationship of database Table
Database Relationship is a vast subject in database system, which I will discus latter, but for now, I want to give you a brief knowledge about the database relationship.
Here, we will create two tables to store each user’s registration information. One is “login” table, which we already created in the early season, and the other is “user_information” table to store the detailed information of the users. To find out a particular user’s information you need a relationship column to relate with both the login and user_information tables. These columns must be unique in this case and both the columns in each table will hold the same unique data. In this case, userName will be the unique column for both of the tables to identify the particular information of a user.
continue...
marlopax
Sunday, January 24, 2010
Create “user_information” table:
• Create a table in the same database named user_information.
• Create required columns named First Name, Last Name, Sex, Age, Country, Email ID, Date and userName.
• userName column will be same as you did in the login table with Primary Key.
• FirstName VARCHAR (40) user’s first name.
• LastName VARCHAR (50) user’s last name.
• Sex CHAR (10).
• Age TINYINT (2) Attributes “UNSIGNED”.
• Country VARCHAR (50).
• Email VARCHAR (50) user’s e-mail address.
• CreateDate DATE.
Storing Data into Database:
Storing data into database with php from Flash Lite 1.1 need the SQL code to INSERT into the database. The code bellow will generated from the phpadmin page from the localhost server page. You will get this option “Create PHP Code” after inserting a data from the Insert tab. You can follow both the code to know how php store data into the database table.
Table user_information:
$sql_01 = "INSERT INTO `db01sep2009mob_app`.`user_information` (`FName`, `LName`, `Age`, `Sex`, `Country`, `CreateDate`, `Email`, `userID`) VALUES (\'your first name\', \'your last name\', \'your age\', \'your sex\', \'your country\', \'date in this format 0000-00-00\', \'your email address\', \'your user name\');";
Table login:
$sql_02 = "INSERT INTO `db01sep2009mob_app`.`login` (`userID`, `Password`, `createDate`,`subscribe`) VALUES (\'your user name\', MD5(\'your password\'));";
The above code will insert the data into two tables in the database “db01sep2009mob_app”.
continue...
marlopax
Tuesday, January 26, 2010
Editing User Information:
First of all, it is a thumb rule that an user has to login before editing the user information, and when user click to edit the information the form should filled up with the old entries from the database, so the user will able to change the right field.
Therefore, to edit the user information the structure will be like this:
1. Login before Edit
2. When user clicks to edit, flash application will call a php script, which execute the old entries from the database of the particular userID into the flash form.
3. When user saves the changes, the flash again call a php script, which will update the data into the database.
4. Return success message to flash application.
continue...
marlopax
Friday, February 26, 2010
Extract data into Edit Profile:
After a successful login, user will able to access the edit profile page/form in the flash application. There is a chance to take more information from your members, such as personal number, postal address etc. for that you have to construct some extra field in your database and some extra line script in php as required.
It is not required to pull data to change password. You can directly check the old password from the login variable and can compare the password from the old one and it is the same process to check the new password with the confirm password variable. After the check with if ( ) { } else { } statement, flash can sent the new password into the database to replace from the old one through PHP.
For editing of the personal data, it is necessary to extract the data from the database, and to do that the following PHP code will extract or to pull out the data/information into the edit profile input field.
PHP Code:
if($whatToDo=="Extract"){
mysql_connect($host,$user,$pass);
mysql_select_db($database);
$table="user_information";
$userName=$_POST[“userName”];
$query = mysql_query("SELECT * FROM $table WHERE userID = '$userName'");
$result = mysql_num_rows($query);
$row=mysql_fetch_row($query);
echo “&nData=".$result."&FirstName=".$row[0]."&LastName=".$row[1]."&Age=" .$row[2]."&Sex=".$row[3]."&Country=".$row[4]."&CreateDate=".date('m/d/Y',strtotime($row[5]))."&Email=".$row[6]. "&userName=".$row[7]."&";
}
“nData” an Extra Variable:
In the echo part of the above php code, I use “nData” variable to send a value into flash, just for future work of EMI application. The “nData” variable sends the results of the query, means the number of rows found with the same userID, which is here always be “1” as the userID is unique and MySQL never store similar data in primary keys. Actually, this is a good habit to keep your thinking continuous towards the future of your applications. To do such things, which you can do in future, you have to keep options from the beginning. I must say that there is no end of future progress and development, but it not meant that every development had a complete plan from the beginning. Flexibility of changing things or adding new features is always been good for your work and to the business. Here, “nData” variable could help for FM (fraud Management), or to send the Error messages into your Flash Lite application. In future post, I will do something with this “nData” variable. For now just bother this extra bytes variable into your application.
continue...
marlopax
Thursday, March 04, 2010
Now, the questions come around:
How you are planning to give access to your users to edit their information. Will any users can able to destroy their information from database, or can able to change their names with just less than three letters or can submit an invalid Email ID. Many functions will possible with backend programming, even you can also do with front-end programming whenever it needed or as your application needs. The following Flash Lite front-end programming code will set the validation of the FName Input Text Field.
Flash Lite Code:
fscommand2("SetInputTextType", "FName", "Alpha");
if (length(FName)<3) {
FName="Invalid";
}else if(FName eq "Invalid"){
FName="";
}else{
FName=FName;
}
The Alpha in fscommand2 will only allow users to type only alphabets even it denies to type space. Therefore, nobody can type more then one word in this input text field. After all the validation, just fire the EMI.php by POST method and with whatToDo = “Edit”;. The following php code will update the data of the particular user.
PHP Edit Profile Code:
if($whatToDo=="Edit"){
$userName=$_POST["userNameSent"];
$FName=$_POST["FName"];
$LName=$_POST["LName"];
$Age=$_POST["Age"];
$Sex=$_POST["Sex"];
$Country=$_POST["Country"];
$Email=$_POST["Email"];
$Address=$_POST["Address"];
$Mobile=$_POST["Mobile"];
mysql_connect ($host, $user, $pass);
mysql_select_db ($database);
$table="user_information";
$update = mysql_query("UPDATE $table SET FName = '$FName', LName ='$LName', Age = '$Age', Sex = '$Sex', Country ='$Country', Email = '$Email', Address ='$Address', Mobile = '$Mobile' WHERE userID= '$userName'");
$result=mysql_affected_rows();
if($result==1){
echo "&result=Success&";
}else{
echo “&result=Error&”;
}
}
continue...
marlopax
Friday, March 12, 2010
Agency Component in Flash Lite 1.1 PHP & MySQL:
To start with this section of EMI +, you need separate tables in your database to put the name and descriptions and the other information of the associate companies. For the EMI discussions I have create tables in the same database.
Company List database table:
• Create a company list table, named – company_list
• Create three columns to hold the name, country and company’s information data
• Name VARCHAR (100) – the name of the company must be unique.
• CompanyCode CHAR (20), Primary Key – code number of company
• CompanyInfo VARCHAR (255) – brief information about the company
Insert some company’s name, some unique company code and other information in it.
Create another table for the agent.
Agent List database table:
• Create a agent list table, named – agent_list
• Create five columns in the agent_list table
• userID VARCHAR (50) – for user’s ID
• Agency VARCHAR (100) – for the name of the company
• agencyDate Date – create date of the agency
• agencyCode VARCHAR (10), Primary Key – the agency code column holds the primary key for this agent list table.
• agentArea VARCHAR (50) – the location of the agent
Leave the agent list database empty, mean do not insert any data in it. Create another table named company_locate, which holds the information of which location the company have its businesses.
Company Location database table:
• Create a company location table, named – company_location
• Create three columns in it
• CompanyCode CHAR (20) – in this table it will not be a primary key
• CountryCode CHAR (10) – it stores the code of the country
• CountryName VARCHAR (50) – the name of the country
In this data table, we will store the country code, company code and the name of countries. One thing keeps in mind to buildup any database is not to store unnecessary data or never construct data table columns that have no use. That will confuse your purposes and occupies space in your database. As here in this company location table, I create a column to hold the name of the countries, which will unnecessary, to get a query of a particular company location you need only the country code. However, you might have some other plan to use the data in the country column.
continue...
marlopax
Thursday, March 25, 2010
Country Code datable named “country_code”:
Create another data table to store the country code and country name. Stop creating this manually, because we are going to talk about how to create a database table through php. In this discussion, you will know/learn how to create table and columns in it and how to insert huge data from a text file into MySQL database through PHP.
To create a table in a database with PHP, we need to connect the database first, then to select the database and then to create the table with a name of that table. At first, we have to create a well format data in a text file with .txt extension, which we can easily use notepad to do this and save the text file in www root folder. The data we are going to store into the text file is only the country code and the country name, which will structure like the following example; you can also download the entire data in .txt format here:
http://www.marlopax.com/countryCode/countryCode.txt
Text File data structure:
AC:Ascension Island
AF:Afghanistan
AL:Albania
continue...
marlopax
Friday, April 09, 2010