#native_company# #native_desc#
#native_cta#

Using PHP and MySQL with Flash Page 5

By Jeffrey F. Hill
on December 14, 2001

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 two lines of this code performs 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, i.e. it’s now equal to 1.
The most important thing to remember when retrieving any type of data from a php script to a flash movie is that it must return a file with nothing on it except text in variable/value format. For example, if the file you are returning has any type of html formatting it will cause an error. “<html><head></head>Status=Success&CheckLog=1” will not work, but “Status=Success&CheckLog=1” will. A good way to check this and to make sure the script is working is to type the url to the script in the browser window and review what is printed to the screen.
Also note that there are better ways to return variables to a specific level in a flash movie, printing out _root before the variable name works in this case but may not in others. It’s important to remember that variables are returned to the movie clip that the request was sent from unless specified otherwise.

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9