dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Writing to a database without refresh

  1. #1
    Member
    Join Date
    Oct 2000
    Posts
    79
    I'm pretty sure I've figured out how to GET info from a database without the need to refresh the page with the loadVariable command.

    However, I can't figure out how to PUT info into the database without refreshing.

    The only way I know how to move info to the database is by calling a PHP script with the getURL command which as far as I can tell forces you to "get a URL" thus loading up that PHP page.

    I'd like to be able to not only get info but also take form input and push it to the database without leaving my movie.

    How can that be done? How do you handle the issue of not proceeding till the info has been written (as is the case when you're getting info)??

    Any help would be greatly appreciated!!

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Posts
    139
    Originally posted by SoccerFan
    The only way I know how to move info to the database is by calling a PHP script with the getURL command which as far as I can tell forces you to "get a URL" thus loading up that PHP page.
    Although it seems strange, you actually use LoadVariablesNum (rather than getURL) to call a PHP script that will write variables to a database.

    Let's imagine your variables are on level0. Use the following to trigger the PHP script:

    Code:
    loadVariablesNum ("thephpfile.php", 0, "POST");
    This will actually send all the variables on level 0 to the PHP file speficied, wherein you can just address them like any other variables.

    The Flash manual doesn't really make clear that this is the way to do it, and the whole syntax is misleading, since you're not really Loading variables with this command, but Sending them. Oh well, it works. That's all that matters!

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    79
    Thanks! That works great, just two questions about it.

    This may be a newbie type question, but what in the heck is "level 0"?? It works great, posts right into my MySQL database, but I'd like to know what that means....

    Secondly, how can I easily test to make sure that the values got posted correctly? When I hit submit, it just sits there dead to the world, which is, of course, what I wanted (no refresh)!! However, it looks "dead". I can easily stick in a GoToandPlay type command in the actionscript and make it look really nice, but what if the post fails? How might I check to make sure the post was successful before moving forward in the movie?

    Thanks again!!

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Posts
    139
    1) level 0 just means "the main stage". if you load other movies on top of the main stage using actionscript, you put them on levels so that you can maintain a stacking order. Don't worry about it for the time being. the "0" in the loadVariablesNum command just refers to variables on the main stage in some way. Not really important as long as it works.

    2) OK. In your PHP file, set a variable called $success to 1 if the variables get saved correctly, or to 0 if they don't. Then, after you use the loadVariablesNum command in Flash, simply use this code to check (in Flash, not PHP):

    Code:
    if (success) {
      // ok, it worked, so do whatever you need to do
    } else {
      // it didn't work, do whatever you need to do!
    }
    Does that work for you?

  5. #5
    Member
    Join Date
    Oct 2000
    Posts
    79
    Work for me?! It's perfect!!

    Thank you very much, that really did it!

  6. #6
    Member
    Join Date
    Oct 2000
    Posts
    79
    OK, I'm having a bit of a problem.....!!

    Why is this not working? I'm sure I'm not using the right type of program flow. This is the actionscript attatched to the submit button:

    on (release) {
    loadVariablesNum ("nameinsert.php", 0, "POST");
    }

    if (success) {


    gotoAndPlay (3);


    } else {


    gotoAndStop (2);


    }

  7. #7
    Member
    Join Date
    Oct 2000
    Posts
    79
    OK, I got the error resolved, but it's still not quite there:

    on (release) {
    loadVariablesNum ("nameinsert.php", 0, "POST");

    if (success) {


    gotoAndPlay (3);


    } else {


    gotoAndStop (2);


    }
    }

  8. #8
    Member
    Join Date
    Mar 2001
    Posts
    36
    soccer fan,

    this is what you had:

    on (release) {
    loadVariablesNum ("nameinsert.php", 0, "POST");

    if (success) {


    gotoAndPlay (3);


    } else {


    gotoAndStop (2);


    }
    }

    ok...this is my suggestion...

    on (release) {

    loadVariablesNum ("nameinsert.php", 0, "POST");
    gotoAndPlay (3);

    }

    and then on frame 5 you can have a gotoAndPlay (3); so its a repeating loop...then on frame 4 you can have

    if (success) {


    gotoAndPlay (3);


    } else {


    gotoAndStop (2);


    }

    this will check if success is true until it is or not...I think when you had it on your button didn't give the variable time to process in php

    hope that helps

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