Creating Flash site, need simple mailing list sign up using PHP/MySQL DB

Hi, I want to create a simple mailing list signup form for my site (which will be entirely in flash) similar to the one here: accept without the zip option.

I have access to MySQL using phpMyAdmin. I was thinking that I could just store the adresses to the db. Problem is, I don't know how to do it in flash mx. I am a novice when it comes to flash, and I'm sure I'll have many questions for you. I also have several other questions about the site in general that need to be answered if anyone is interested in investigating them.

So, Problem: need functional mailing list in MX.
1) How do I integrate the form and PHP into MX so that PHP sends the addresses to the db?
2) What's the easiest way to setup the db (I don't know that either)?
3) Once the db has the addresses stored, how can I retrieve them and send out my mailer?
4) I also have Mojo Mail on my server; is there a way that I can use it to collect the names from the db and send them?

I really need answers as soon as possible.

Remember, I don't know what I'm doing, please try to simplify your explainations.

If anyone knows of any relevant tutorials, please post them as well.

Thanks very much for any help.
Who is Participating?
mrdilliardConnect With a Mentor Commented:
There's actually two parts to this, since Flash doesn't support direct database access without a component.

I would go ahead and create your database, and then your php page first.

I made a table in my database called MailingList, with 3 fields.
1. MailID of type INT that's an auto-incrementing field/primary key
2. Address of type VARCHAR, length 50
3. Name of type VARCHAR, length 50

on my php page, I have this code:

      $conn = mysql_connect('SERVER_NAME','USERNAME','PASSWORD');
      $sql = "INSERT INTO MailingList (Address,Name) VALUES ('$EmailAddress', '$Name')";

so the page has to be sent in this format:

Now that that part's set up, we just have to have flash interact with it.

First, you need to create 2 text fields and make them input text fields in the properties inspector. You'll have the option for static text, dynamic text or input text...choose input for both.

I named the first one txtEmailAddress and the second one txtName, for consistency with the variables we'll send. Select the text field, and you can name it in the properties inspector, right under where you made them input text fields. Also, make sure you display their outlines. You'll press a button that's in a set of 3 buttons in the middle of the properties inspector. It'd also be a good idea to put text fields next to them to say what they are. i.e., put a text field with the text "email address" next to the txtEmailAddress field, so people can tell what they're putting into the field.

We also need a button. I made a movie clip named mcSubmit and put a rectangle with some text in it. It doesn't matter what you name it when you create it, but it needs to be named (in the same way as you name text fields) mcSubmit for the code I'm going to create. If you change mcSubmit to something else, you need to change the button/movie clip's name on the stage as well as in the code.

The basic idea is to use the built in LoadVars function, which works pretty well, once you get the hang of it. Essentially, it sends out variables to a page and gets any variables on the page and loads them back in. You can choose to only send variables, or to only load variables, but we're going to do both, so that we don't have to open a new window.

First, create a new layer and call it actions. Click on its first frame and hit F9 to bring up the actions panel.

Paste the following code in:

mcSubmit.onRelease = function() {
      var lvMailingList:LoadVars = new LoadVars();
      lvMailingList.onLoad = function(success:Boolean) {
            if (success) {
                  //anything to do after it's been entered into the database
      lvMailingList.EmailAddress = txtEmailAddress.text;
      lvMailingList.Name = txtName.text;
      lvMailingList.sendAndLoad("", lvMailingList, "POST");

I'm assuming you have MX 2004. If so, this code should work.

You can use my examples if you want.

Have fun!
imawakeAuthor Commented:
imawakeAuthor Commented:

Thanks so much for the help. I'm working on it. I just have MX but I don't suppose that that really matters? I'll let you know how it goes.

i don't think mx will let you do strict data typing, so change this line
 var lvMailingList:LoadVars = new LoadVars();
 var lvMailingList = new LoadVars();
All Courses

From novice to tech pro — start learning today.