A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Send/Retrieve from a database to flash ?

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

    Send/Retrieve from a database to flash ?

    Hey guys, was wondering if you could help me out. I have a project where i have a database containing all of the users of a particular application. The database contains the basic things usernames user paswords and other information specific to the flash file.

    I havent done any work using a database and flash. So what i want to know is how do i set it up and what code do i use in my flash file to recieve information from the database and how do i save to the database?

    Thanks in Advance

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

    first of all you will have to find something (php is a good candidate) on your server that lets you access the database - or, in case this is not on the web but on your local system, something that acts like a webserver

    Musicman

  3. #3
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Yep its online so its a web server.Going to be either asp or php. What do i need next ?

  4. #4
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Does anyone have an opinion?

  5. #5
    Junior Member
    Join Date
    Apr 2004
    Posts
    17
    What kind of database is it?

    I connect all the time using ASP and SQL

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

    sample database definition for mysql
    create table users (
    id int not null auto_increment,
    user varchar(20),
    password char(32) binary,
    email varchar(80),
    age tinyint, -- or whatever your fields are
    primary key (id),
    unique (user)
    );

    sample php script to add a new user
    (flash form fields should be named user, password, etc like in the database; form should send POST method)
    Code:
    <?
    include "db.php"; // include mysql password etc.
    mysql_connect($DBHOST, $DBUSER, $DBPASS) or die("&status=cannot connect database server " . mysql_error());
    mysql_select_db($DBNAME) or die("&status=cannot select $DBNAME database " . mysql_error());
    $vars = array("user","password","email","age");
    foreach($vars as $var)
     $$var = $_POST[$var];
    $status = @mysql_query("insert into users (user, password, email, age) values ('$user', md5('$password'), '$email', '$age')");
    if(!$status)
      if(mysql_errno() == 1062)
         print "&status=duplicate value";
      else
         print "&status=problem inserting " . mysql_error());
    else
      print "&status=user added";
    ?>
    For retrieving all users, you would usually choose either a flash tabular form or a textfield. For the multi-cell form, consider a php script like this
    Code:
    <?
    include "db.php"; // include mysql password etc.
    mysql_connect($DBHOST, $DBUSER, $DBPASS) or die("&status=cannot connect database server " . mysql_error());
    mysql_select_db($DBNAME) or die("&status=cannot select $DBNAME database " . mysql_error());
    $result = mysql_query("select * from users ...."); // the ... would later handle a search function
    $n = 0;
    while($row = mysql_fetch_array($result))
    {  print "user$n={$row['user']}&email$n={$row['email']}&age$n={$row['age']}";
       $n++;
    }
    print "&users=$n";
    ?>
    Musicman

  7. #7
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Thanks very much for that music man. Gonna read over it properly and try it out be waiting for questions

  8. #8
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    OK i dont know much about php i tried to understand what is probaly to you is very basic but to me im a little confused.

    So basically i have

    Flash File

    PHP Page File

    A database File

    Ok ive got the flash file and data base business sorted but im having trouble managing the php page. Is their anyway you can help me out. I dont have any specific questions. Im just confused in general.

    Do you mind just doing a algorithm of how the php file should work ?

    Thanks in Advance


  9. #9
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    I just came across something that i think will be a problem.
    In my flash file on the first frame i load the data to an empty mc.

    serverData.loadVaribles("http://freshvision.com.au/data/db.php");

    Does that load all the data my php page gathers from the database. Because my data base file has thousands of records. I dont want to load entire database files just records in the data base that match criteria in the flash file.

    Like if the ID and PASSWORD feilds match in a row then send all information for that users ID and store them as seperate varibles in an empty mc.

    Problem is the Php page and the loading entire database files problem.

    Thanks again !

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