Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash & PHP Question... 1

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I am trying to write a form using Flash, PHP & MySQL. This form is for creating new accounts. What I want to be able to do is enter info into all fields, press a "submit" button, the info is inserted into a table and then the user is taken to a new html page. As it is now, I can enter info into fields, press submit and the info is successfully entered into the table.
However, it appears as if I am getting stuck in some kind of infinite loop as the submit buttons continuously clicks and I have to close the browser. I believe my problem is in my passing variables from PHP into Flash. Here is the PHP code:

<?
//this pulls the variables from the flash movie when the user hits submit
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$city=$_POST['city'];
$account=$_POST['account'];
$password=$_POST['password'];
$age=$_POST['age'];

//connect to database
if ($firstname && $lastname && $email && $city && $account && $password && $age){
$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("MySQL database", $dbh);

//make query
$query = "INSERT INTO accounts (accountname, PASSWORD, FirstName, LastName, Email, City, Age) VALUES ('$account', '$password', '$firstname', '$lastname', '$email', '$city', '$age')";
$result = mysql_query( $query ) or die ("didn't query");

//see if there's an EXACT match
if ($result == 1){
print "Success&checklog=1";
} else {
print "Failure&checklog=2";
}
}
?>

Below is the ActionScript for the Submit Button:

on (release, keyPress "<Enter>") {
//checks to see if there is something in both the name
//and password
if (_root.firstnameinput.text != "" && _root.lastnameinput.text != "" && _root.emailinput.text != "" && _root.cityinput.text != "" && _root.accountinput.text != "" && _root.passwordinput.text != "" && _root.ageinput.text != "") {
loadVariablesNum("new.php", 0, "POST");
}
else {
_root.gotoAndStop(2);
_root.checklog=0;
_root.firstnameinput.text="";
_root.lastnameinput.text="";
_root.emailinput.text="";
_root.cityinput.text="";
_root.accountinput.text="";
_root.passwordinput.text="";
_root.ageinput.text="";
}
}

And here is the final bit of ActionScript which is on the first fram of the movie:

stop();
//stops the movie on the login page

Selection.setFocus(firstnameinput);
//this puts the cursor in the first box

this.onEnterFrame = function () {
if(_root.checklog == 1){
_root.getURL("home.htm");
}
if(_root.checklog == 2){
_root.gotoAndStop(2);
_root.checklog=0;
_root.firstnameinput.text="";
_root.lastnameinput.text="";
_root.emailinput.text="";
_root.cityinput.text="";
_root.accountinput.text="";
_root.passwordinput.text="";
_root.ageinput.text="";
}
}
//the onEnterFrame constantly checks to see if the PHP
//script has sent the variable 'checklog' back to the
//movie and directs the people accordingly

You can view the page and see the problem I am having at Just click on the "Create New Account" box in the green box and enter some bogus info.

Thanks in advance for any help! It is greatly appreciated.
 
I'm a little confused with the "loop" you think you're getting into. There's no loop structure in your PHP script so the only thing I can think of is that when you create your SWF file, you're not clearing the "loop" feature of the clip.

There's always a better way. The fun is trying to find it!
 
Thanks for the reply Tviman,
Maybe loop isn't the best way to put it. The problem is that when I click on submit, the info is inserted into the table as I want it to be, but then I am not escaping from the OnEnterFrame function.
If you have a couple of seconds to try it out at and then click on "create new account" you will see my problem better when you click on "submit".
Thanks again...
 
try adding delete this.onEnterFrame

Code:
this.onEnterFrame = function () {
    if(_root.checklog == 1){
        _root.getURL("home.htm");

        delete this.onEnterFrame
    }
    if(_root.checklog == 2){
        _root.gotoAndStop(2);
        _root.checklog=0;
        _root.firstnameinput.text="";
        _root.lastnameinput.text="";
        _root.emailinput.text="";
        _root.cityinput.text="";
        _root.accountinput.text="";
        _root.passwordinput.text="";
        _root.ageinput.text="";

       delete this.onEnterFrame
    }
}

Regards,

Martin

Gaming Help And Info:
 
YES! That fixed it. A HUGE thanks to MJB3K for the help. I have spent literally hours the past couple of days trying to solve this. What a life saver. Thanks again!
 
Hi dmears1. do you think you could send me a .fla and a .php page with a similar example, because i been spending lots of time trying to get a similar sort of thing working but with no luck.

Email it to downloads@webrevolt.biz please

Thank you if you do so!

PS. im glad your thing works :)


Regards,

Martin

Gaming Help And Info:
 
MJB3K,
I've sent you the FLA and PHP file. Hope they are of some help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top