A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Flash to PHP to Mysql help.

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976

    Flash to PHP to Mysql help.

    Hey peeps, ive been fiddling with mysql and php on a newbie level, and i was wondering if you could help me out. I was just wondering how things work. How im supposed to pack things and send it to the next thing. Like how do i pack and send a variable called numCo = 7; and send it to php. And then have php insert that var into mysql.

    I found this in a tutorial i was working with and realise its how you submit the info to my sql
    PHP Code:
            //  Setup query
            
    $q "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
                
    ."VALUES ('".$_POST["username"]."', "
                
    ."PASSWORD('".$_POST["password"]."'), "
                
    ."'".$_POST["email"]."')";
            
    //  Run query
            
    $r mysql_query($q); 
    But how do i set a variable up in flash to send to php.

    Its really urgent ive been trying to understand this for a while but i keep finding different ways people do it and im getting confussed.

  2. #2
    Senior Member bs_grewal's Avatar
    Join Date
    Dec 2002
    Posts
    548
    first of all u need to create 3 text boxes in flash file with the var names "username,password,email"

    then place a button for submit and use this script on the button

    on (release, keyPress "<Enter>") {
    getURL("https://www.domainName/login.php", "", "POST");
    }

    i don't know is ur query in php file is ok or have some error, but this action send the data out of flash.
    Thanks
    Baljit Singh Grewal
    Click here to email me
    Messengers: [email protected]

  3. #3
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    so do i have to have the variables i want to post in text boxes? How do i send them if their on the _root timeline?

    I cant see any variables declared in this
    Code:
    on (release, keyPress "<Enter>") {
    getURL("https://www.domainName/login.php", "", "POST");
    }
    how does php know which variables to read?

  4. #4
    Member
    Join Date
    Dec 2004
    Posts
    53
    Hi there,
    Try something like:
    code:

    on (release, keyPress "<Enter>") {
    getURL("https://www.domainName/login.php?var=whatever", "GET");
    }



  5. #5
    Senior Member bs_grewal's Avatar
    Join Date
    Dec 2002
    Posts
    548
    sorry
    use this

    Originally posted by bs_grewal
    first of all u need to create 3 text boxes in flash file with the var names "username,password,email"

    then place a button for submit and use this script on the button

    on (release, keyPress "<Enter>") {
    getURL("https://www.domainName/login.php?username=vari&password=var&email=var", "", "POST");
    }

    i don't know is ur query in php file is ok or have some error, but this action send the data out of flash.
    Thanks
    Baljit Singh Grewal
    Click here to email me
    Messengers: [email protected]

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    it is generally considered a bad idea to send passwords via the query string, bacause they will show up in the browser history
    If you want to use this kind of technique, the coding would be
    geturl("http://www.somesite.com/script.php?var1="+var1+"&var2="+var2,"");

    If you want to send just specific vars to a new page, with post, use loadvars.send()

    Musicman

  7. #7
    Senior Member bs_grewal's Avatar
    Join Date
    Dec 2002
    Posts
    548
    yh Musicman, u r right
    i uselly connect database with asp so i use flash objects to send this kind of data, i m not a php expert so i suggest this method.
    Thanks
    Baljit Singh Grewal
    Click here to email me
    Messengers: [email protected]

  8. #8
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Thanks guys, another quick question is,

    In a tutorial i seen them put a _root in the first arrgument instead of "" whats the difference?

    so this

    Code:
    getURL("https://www.domainName/login.php?username=vari&password=var&email=var", "", "POST");
    change to this.

    Code:
    getURL("https://www.domainName/login.php?username=vari&password=var&email=var", _root, "POST");

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    the empty argument seems to be one of those nice little undocumented features that work.
    It is up to you to find out whether it is equivalent to _root or this (and rather irrelevant if you only use that code on the main timeline)

    @bs_grewal: flash does not know the difference between asp and php servers

    Musicman

  10. #10
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    The same tutorial that showed me that _root thing which doesnt seem to work show me this now it doesnt work but i cant get it to work.

    everything is set up the vars are in place but i think its this script thats bad

    Code:
    on(release) {
    var lowscore = _root.lowscore;
    var lowplayer = _root.lowplayer;
    var pAbility = _root.pAbility;
    var scoreid = scoreid;
    var num = _root.num;
    loadVariables("http://localhost/updatescore.php", _root, "POST");
    }
    now i dont see the variables passed to the script in the line loadVariables("http://localhost/updatescore.php", _root, "POST");

    And their is also a input text box on the time line with the name newplayer on it that is suppossed to get sent to it.

    Now it doesnt seem to work. I think i can see why bt i dont know how to re write the

    loadVariables("http://localhost/updatescore.php", _root, "POST");

    line

  11. #11
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    if your variables are on the main timeline, the code before loadvariables is simply unnecessary.
    If they are in a movieclip, the code will not send anything reasonable

    I just replied to another thread and suggested use of loadvars object in place of loadvariables - this would be an option for you as well

    Musicman

  12. #12
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Yeh the button is inside a movieclip and the actions on the movieclip. Is

    Code:
    onClipEvent(data){
    gotoAndStop(20);
    }
    So on this line how does it know what variables to pass?

    Code:
    loadVariables("http://localhost/updatescore.php","", "POST");
    Shouldnt that line contain some sort of variable names like suggested by swap_meet. Or does flash send every variable to the php file? Seems pointless.

    Like shouldnt it be like this
    Code:
    loadVariables("http://localhost/updatescore.php?lowplayer=lowplayer&hiplayer=hiplayer","", "POST");
    I dont know the propper syntax. For the ?lowplayer part. Does it go.
    ?("the variable name in the php file")=("where the variable is in flash)

    so like this

    Code:
    ?phpvarname=_root.flashvarname
    ??

  13. #13
    Member
    Join Date
    Dec 2004
    Posts
    53
    Hi again hooligan (fellow Melbournian),
    You can define your variables if you use what Musicman suggested (using the LoadVars object).
    Here is an example:
    Code:
    myData = new LoadVars()
    myData .pass_var = this.pass_var;
    myData .sendAndLoad("http://localhost/updatescore.php, myData , "POST")
    
    myData.onLoad = function(){ 
    placeData();
        };
    placeData= function(){
    if(myData.checklog == 1){
        this.var_name = myData.status;
        this.gotoAndPlay(1);
    } else if(myData.checklog == 2){
        this.var_name = myData.status;
        this.gotoAndStop(3);
    }
    }
    then your PHP may look soething like:
    PHP Code:
    $pass_var $_POST['pass_var'];

    // do whatever you like here, query, update etc.

    //output for flash
    if ($result)
    {
       print 
    "&status=DATA TRANSFER COMPLETE&checklog=1";
       } else {
       print 
    "&status=THE DATA COULD NOT BE TRANSFERED&checklog=2";
       }
       print 
    "&";

    HTH

  14. #14
    Senior Member bs_grewal's Avatar
    Join Date
    Dec 2002
    Posts
    548
    Originally posted by Musicman

    @bs_grewal: flash does not know the difference between asp and php servers

    Musicman
    yes Musicman flash doesn't know the difference between asp and php but i was talking about myself that i don't know the php.
    Thanks
    Baljit Singh Grewal
    Click here to email me
    Messengers: [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center