A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Using flash to build a register page

  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122

    Using flash to build a register page

    Hi, i have set up this register page:
    http://www.kjslaundry.com/register.php

    it's working fine, with mySQL and php. what i would like to do, is instead of it being a html page, make it a flash page. How do i get flash to talk to the database?

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    Just build your form in Flash, and pass the variables to PHP using LoadVars:

    http://www.macromedia.com/livedocs/f...html#wp3994770

    K.

  3. #3
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    any more info would be great. like a link to a tutorial.

    but thanks anyway.

  4. #4
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    i tried to understand this but i'm finding it really difficult. i've got the php file working perfectly. i just need to get the swf to send the variables to the php file.

    HELP!

  5. #5

  6. #6
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    god, i've looked at so many tutorials and i still don't get it.

    i would have thought it would be easy just to send the data from flash to the php.

    if anyone can help i've included some files.
    Attached Files Attached Files

  7. #7
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    HELP!!!

    right, i'm using this php script:
    <?
    /*
    insertscore.php: inserts record into kjsLaundry table, returns new
    record id and status to Flash
    */

    // fill with correct data for your server configuration
    $server = "localhostt";
    $username = "user";
    $password = "password";
    $database = "database";
    if (!mysql_connect($server, $username, $password)) {
    $r_string = '&errorcode=1&';

    } elseif (!mysql_select_db($database)) {
    $r_string = '&errorcode=2&';

    } else {
    $ins_str = "INSERT INTO maillist VALUES (NULL, '".addslashes($_POST['name'])."', '".$_POST['email']."', '".$_POST['address']."')";

    if (!mysql_query ($ins_str)) {
    $msg = mysql_error();
    $r_string = '&errorcode=3&msg='.$msg;
    } else {
    // pass back id of inserted record
    $id = mysql_insert_id();
    $r_string = '&errorcode=0&id='.$id.'&';
    }
    }

    echo $r_string;
    ?>



    and i'm using this actionscript:

    var submitListener:Object = new Object();
    submitListener.click = function(evt:Object) {
    var result_lv:LoadVars = new LoadVars();
    result_lv.onLoad = function(success:Boolean) {
    if (success) {
    result_ta.text = result_lv.welcomeMessage;
    } else {
    result_ta.text = "Error connecting to server.";
    }
    };
    var send_lv:LoadVars = new LoadVars();
    send_lv.name = name_ti.text;
    send_lv.email = email_ti.text;
    send_lv.address = address_ti.text;

    send_lv.sendAndLoad("http://localhost/insertscore.php", result_lv, "POST");
    };
    submit_button.addEventListener("click", submitListener);
    stop();
    //


    the insert score.php seems to be working because it's entering blank info into the database. but i can't work out how to get the swf to enter the info into the php. HELP!!!!

  8. #8
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    now i'm using this actionscript:
    var send_lv:LoadVars = new LoadVars();
    send_lv.name = name_ti.text;
    send_lv.email = email_ti.text;
    send_lv.address = address_ti.text;
    stop();

    //

    with this on a button:
    on (release) {
    send_lv.send("http://localhost/insertscore.php", "_blank", "POST");
    gotoAndPlay(2);
    }

    //

    it seems to be sending something from the swf file, but then in the msql database for the entries it says undefined.

  9. #9
    I'm your boogie man!
    Join Date
    Aug 2003
    Location
    Where hope and daylight dies
    Posts
    21
    instead of "_blank" you have to send the send_lv object, something like this:

    send_lv.send("http://localhost/insertscore.php", send_lv, "POST");
    -> web || blog <-

  10. #10
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    it's still opening up a new window.


    now i'm using this php code:
    <?
    /*
    insertscore.php: inserts record into kjsLaundry table, returns new
    record id and status to Flash
    */

    // fill with correct data for your server configuration
    $server = "localhost";
    $username = "%";
    $password = "%";
    $database = "kjslaundry";
    if (!mysql_connect($server, $username, $password)) {
    $r_string = '&errorcode=1&';

    } elseif (!mysql_select_db($database)) {
    $r_string = '&errorcode=2&';

    } else {
    $ins_str = "INSERT INTO maillist VALUES (NULL, '".addslashes($_POST['name'])."', '".$_POST['email']."', '".$_POST['address']."')";

    if (!mysql_query ($ins_str)) {
    $msg = mysql_error();
    $r_string = '&errorcode=3&msg='.$msg;
    }
    }

    echo $r_string;
    ?>


    and this actionscript:

    var send_lv:LoadVars = new LoadVars();
    send_lv.name = name_ti.text;
    send_lv.email = email_ti.text;
    send_lv.address = address_ti.text;
    stop();


    and it's entering blank infomation.
    Last edited by martinstaceyuk; 03-01-2006 at 11:42 AM.

  11. #11
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    here are the new files. if anyone could take a look at them and tell me what i'm doing wrong. i've managed to get the swf talking to the php, and the php talking to the mysql. but it's not entering what i am entering in the swf. it's just blank.
    Attached Files Attached Files

  12. #12
    I'm your boogie man!
    Join Date
    Aug 2003
    Location
    Where hope and daylight dies
    Posts
    21
    I changed a few things:

    Flash:
    Code:
    submit_button.onRelease=function(){
    	var result_lv:LoadVars = new LoadVars();
    	result_lv.onLoad = function(success:Boolean) {
    		if (success) {
    			result_ta.text = result_lv.welcomeMessage;
    		} else {
    			result_ta.text = "Error connecting to server.";
    		}
    	};
    	var send_lv:LoadVars = new LoadVars();
    	send_lv.name = "Joe";//name_ti.text;
    	send_lv.email = "joe@joe.net";//email_ti.text;
    	send_lv.address = "somewhere";//address_ti.text;
    	send_lv.sendAndLoad("http://localhost/insertscore.php", result_lv, "POST");
    };
    PHP:
    Code:
    <?
    /*
    insertscore.php: inserts record into kjsLaundry table, returns new
    record id and status to Flash
    */
    
    // fill with correct data for your server configuration
    $server = "localhost";
    $username = "root";
    $password = "HEREJE";
    $database = "test";
    if (!mysql_connect($server, $username, $password)) {
    	$r_string = '&errorcode=1&';
    }
     else if (!mysql_select_db($database)) {
    	$r_string = '&errorcode=2&';
    }
    else {
    	$ins_str = "INSERT INTO maillist VALUES (NULL, '".addslashes($_POST['name'])."', '".$_POST['email']."', '".$_POST['address']."')";
    	if (!mysql_query ($ins_str)) {
    		$msg = mysql_error();
    		$r_string = 'errorcode=3&msg='.$msg;
    	} else {
    		// pass back id of inserted record
    		$id = mysql_insert_id();
    		$r_string = 'errorcode=0&id='.$id.'&';
    	}
    }
    echo "&welcomeMessage=This is what i get: ".$r_string;
    ?>
    you never return the "welcomeMessage" variable, instead you returned "errorcode", i removed the "&" so flash will not read this as a variable, but a string

    regards
    -> web || blog <-

  13. #13
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    YOU MY FRIEND ARE A FU*KING GENIUS!!!!!!!!

    THANK YOU SO SO SO SO SO SO SO SO SO [on till infinity] MUCH!!!!

    i was about 1 hour from commiting suicide!!!!!

    one more thing thou,

    in the return box i get: This is what i get: errorcode=0

    is this ok? what's this mean. sorry for being such a dunce with this. i've been trying to figure out php and mysql without knowing anything about it!

  14. #14
    I'm your boogie man!
    Join Date
    Aug 2003
    Location
    Where hope and daylight dies
    Posts
    21
    its the &welcomeMessage variable you where trying to get into flash, in the section:
    Code:
    if (success) {
    			result_ta.text = result_lv.welcomeMessage;
    		}
    you can now use that variable in the way you want, like
    Code:
    if (result_lv.welcomeMessage=="0k") gotoAndStop("welcomescreen");
    -> web || blog <-

  15. #15
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    it all worked fine when i was using my computer as a webserver, but i've tried to upload it to my clients web server on easyhost and for some reason the web browser is reporting an error:
    file not found:
    http://localhost/crossdomain.xml

    this file isn't mentioned anywhere in the actionscript or php.

  16. #16
    I'm your boogie man!
    Join Date
    Aug 2003
    Location
    Where hope and daylight dies
    Posts
    21
    do you have the DNS of easyhost?

    try changing in the php file "$server = "localhost";" to the DNS of easyhost

    that crossdomain.xml is required if you need to interchange data from diferent servers
    -> web || blog <-

  17. #17
    Senior Member
    Join Date
    May 2003
    Location
    London
    Posts
    122
    s'ok, it was a flash security issue. sorted now!

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