• Home
  • About
A journey of a thousand miles begins with a single step
  • Actionscript
  • Sending Variable To MySQL

    Posted on 23rd June 2010
    Posted by herrjunge Categorized Under: Actionscript 6 Commented

    Eventually Flash cannot execute the function on MySQL directly, but through PHP (cmiiw). In order to to send variable to a MySQL database from actionscript, we’re gonna need to understand how PHP and MySQL work. I assume that you have knowledge about MySQL, so we just going deep down on Flash. OK, here we go…

    First setup a database and name it “friend”, and fill it with this query:

    CREATE TABLE IF NOT EXISTS `user` (
      `id` int(10) NOT NULL AUTO_INCREMENT,
      `name` varchar(255) NOT NULL,
      `phone` varchar(50) NOT NULL,
      `email` varchar(100) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=72 ;
    

    on actionscript:
    lets create a MovieClip, say “form”,

    var form:MovieClip = this.createEmptyMovieClip("form", this.getNextHighestDepth());
    

    then, we declare the variable that we want to send by attaching it to previous MovieClip “form”. And also, we want to input that variable dynamically, so we assign it as equal as input text. It means that whatever we type on input text, would be the variable’s value.

    form.name = name_txt.text;
    form.email = email_txt.text;
    form.phone = phone_txt.text;
    

    next, we’re going to send that variable to PHP by using POST method.

    form.loadVariables("input.php","POST");
    form.onData = function(success:Boolean) {
         for (var a in this) {
              trace([a, this[a]]);
         }
    }
    

    on input.php

    <?php
    mysql_connect("host", "user", "password") or die(mysql_error());
    mysql_select_db("friend") or die(mysql_error());
    
    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    
    $sql_user = "INSERT INTO `friend`.`user` (`name`,`phone`,`email`)
    VALUES ('$name', '$phone', '$email');";
    
    $result_user = mysql_query($sql_user);
    ?>
    

    Don’t forget to configure input.php, and it should be work. I think that’s all.

    6 Responses to “Sending Variable To MySQL”

    1. ariawan says:
      June 24, 2010 at 2:17 pm

      weeeshh… jago banget mas muda ini…

      Reply
    2. deni says:
      June 24, 2010 at 6:39 pm

      yeah.. gitu dong mud. gayaan lagi pake english, gak ngerti gue.

      Reply
    3. deny tb says:
      June 24, 2010 at 6:51 pm

      kok g ada file input.php nya…?

      Reply
    4. herrjunge says:
      June 26, 2010 at 4:32 pm

      @ariawan & @deni hehehe… manstab kan gw
      @deny_tb lagian blm jadi dah komen, dah nih hehe

      Reply
    5. Herman Taniwan says:
      July 5, 2010 at 8:45 pm

      Ada juga pecinta flash di negeri tercinta. Salam Flash bro :D

      Reply
      • herrjunge says:
        July 6, 2010 at 12:28 pm

        yoi donk hehehe, salam Flash juga bro

        Reply

    Leave a Reply

    Click here to cancel reply.

    Getting Variable from MySQL »
    • recent entries
    • recent comments
    • archieves
    • Getting Variable from MySQL
    • Sending Variable To MySQL
    • herrjunge: yoi donk hehehe, salam Flash juga b...
    • Herman Taniwan: Ada juga pecinta flash di negeri te...
    • herrjunge: @ariawan & @deni hehehe... manstab ...
    • deny tb: kok g ada file input.php nya...?...
    • deni: yeah.. gitu dong mud. gayaan lagi p...
    • ariawan: weeeshh... jago banget mas muda ini...
    • July 2010
    • June 2010
      • Alternative content

        Get Adobe Flash player

    • Meta

      • Log in
      • Valid XHTML
      • XFN
      • WordPress
    • Categories

      • Actionscript