?
Solved

flash mx form insert data into mysql using php

Posted on 2005-03-16
34
Medium Priority
?
776 Views
Last Modified: 2010-05-18
This is my first question so I apologize ahead of time for any protocol faux pas.

That said what I am trying to do is populate a mysql database through a flash form using a php script . I have 3 combo boxes and 2 input text fields and a submit button.

I have a rough Idea of the scripts I need but I'd rather get the ideal way of doing this so I pulled out all of my scripts and half my hair trying to get this to work. I know the design side of Flash and basic action script but am a php newbie. I have set up a Wamp server to test on and am going to use this on an intranet for a school system. If I could get someone to look at my fla file that would be ideal. Thanks ahead of time.

Here's what I think I have to do

1. use the newLoadVars to get all my data to php using POST
2. connect to the database with mysql_connect and use $insert to populate the mysql database




0
Comment
Question by:nejimmy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 22
  • 12
34 Comments
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556294
ok first of all, can you program in php/mysql/flash?
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556300
what you are trying to do is very easy

what version of flash are you using?
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556312
post your .fla, you php scripts etc.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:ellandrd
ID: 13556313
your*
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556328
<<<< Here's what I think I have to do

1. use the newLoadVars to get all my data to php using POST
2. connect to the database with mysql_connect and use $insert to populate the mysql database

yes you are correct!

what stage are you at?
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556385
BTW

Welcome to Experts-Exchange!
0
 

Author Comment

by:nejimmy
ID: 13556398
I'm not sure how to post my fla file and I have some understanding of programming in flash and php but I am definitely a newbie in this area
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556448
here is how to insert values from flash form using php into a mysql database:

<?php
$your_1st_value = $_POST['your_1st_value'];
$your_2nd_value = $_POST['your_2nd_value'];
$your_3rd_value = $_POST['your_3rd_value'];
$your_4th_value = $_POST['your_4th_value'];
$db = "your_db_name";
$link = mysql_connect("the_host","the_user","the_password");
if (!$link) die ("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
$result = mysql_query("INSERT INTO your_table_name (db_field_name, db_field_name, db_field_name, db_field_name) VALUES ('$your_1st_value','$your_2nd_value','$your_3rd_value','$your_4th_value')") or die ("Insert Error: ".mysql_error());
mysql_close($link);
?>
<script>
<!-- confirmation alert //-->
<!--
alert('New Record Addedd!');
//-->
</script>

if still in doubt about connecting or having other questions feel free to ask!

Sean
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556454
ok have you got access to a server so you can upload the .fla to post it?

you cannot upload your .fla on EE and post the URL here.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556490
i use a free hosting server for uploading my files so other experts can download them

i use

http://www.freewebs.com

set up an account, create a folder for downloads

upload your .fla and post the url here. that way i can download your .fla

when question is answered and closed, take your .fla off the free hosting server

that what i do...

Sean
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556537
p.s have you ever used MySQL before and have you mysql set up on your machine or server?
0
 

Author Comment

by:nejimmy
ID: 13556822
I have a wamp server set up with apache phpmyadmin and mysql running, it's an intranet server.
The fla file I'm using is at
http://www.fpsweb.org/stuff/index.fla 
The php script looks like something I will actually understand!
I'm using FlashMX btw and if I didn't have to do a dozen other things here and have a T1 that was totally full I'd respond quicker. Thanks a lot for your help. What about these Accept buttons do I have to click on them every time or what?
Thanks again in advance
0
 

Author Comment

by:nejimmy
ID: 13556850
I have a wamp server set up with apache phpmyadmin and mysql running, it's an intranet server.
The fla file I'm using is at
http://www.fpsweb.org/stuff/index.fla 
The php script looks like something I will actually understand!
I'm using FlashMX btw and if I didn't have to do a dozen other things here and have a T1 that was totally full I'd respond quicker. Thanks a lot for your help. What about these Accept buttons do I have to click on them every time or what?
Thanks again in advance
0
 

Author Comment

by:nejimmy
ID: 13556864
Stupid 504 timeout sorry for double post
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556893
no only click accept button when you are happy you found a answer to your question. if you click accept now, for example you choose my first answer as accept, i would be awarded the points and you wouldnt have got your solution becuase i was enquiring info my you...

i will download you .fla now

PHP is hard to learn, even though i learned it by University...
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556913
do you know how to check your status on mysql server?

if so, can you logon to mysql and check you status please?

print the results here, as i need to know it, in order to write a PHP script to connect to mysql and populate your database...

0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556942
since your using flash mx, some good advice is to use the flash mx form component as it makes your site look for professional...

0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13556988
you have no actionscript for submitting in your .fla?

do you want me to write the code?

its best to stay refreshing the thread while experts are giving help as you will finish your problem faster...
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13557013
when the user clicks submit, where do you want to bring the user next or what do you want happening next?
0
 

Author Comment

by:nejimmy
ID: 13557014
I want to stay away from components for now, I can only fit so much info into my head at once or I get dizzy. I use phpMyAdmin to access mysql I'm a total gui guy and am going through the painful process of going from right brain to left brain. Do you just need the name of my database and tables and all?
0
 

Author Comment

by:nejimmy
ID: 13557043
I guess I would like the fields to clear and for the user to be able to enter another student. I work for a school system in Nebraska and when you have 500 high school students on your network the bandwith goes in the toliet.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13557080
just need host name, username and i will leave the password field for your to fill in...

ok so after the user clicks submit what do you want happening? redirect to another page or stay in flash?
0
 

Author Comment

by:nejimmy
ID: 13557131
hostname is an internal ip 10.40.4.160 the user name is root  with no password but again this is an intranet not an internet page also I would keep the user in flash I could just have the page reload or have them directed to a sucess frame witha back button or submit another option on it. I know tha mysql is about as unsecure as it can be and I'll deal with that later.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13557146
ok, i'll let you decide what you wnat to do after form is submitted. for now i direct them to another frame...
0
 

Author Comment

by:nejimmy
ID: 13557149
I gotta go get some meds at the doctor will be back -Thanks again man this is a great site the response is alot quicker than I had anticipated. [:{)
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13557785
can you post your database name and the name of the table you are inserting the student details into
0
 

Author Comment

by:nejimmy
ID: 13557824
database name = Entries
table name = Students
and then I basically am filling 5 fields (firstName, lastName, school, event, gender)
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13558828
sorry for the time gaps of posts.

im in europe and i take it your in the states
0
 

Author Comment

by:nejimmy
ID: 13558865
yep though my mom's from the Netherlands so give me Dutch cheese and chocolate over US anyday. No worries, It's not a corporate deadline I appreciate your help
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13563021
here is your php file to populate your mysql db.

im taking it your have it set up as your said...

<?php
$school = $_POST['school_cb'];
$events = $_POST['events_cb'];
$gender = $_POST['gender_cb'];
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];

$db = "Entries ";

$link = mysql_connect("10.40.4.160","root","");

if (!$link)
      die ("Couldn't connect to MySQL");

mysql_select_db($db , $link) or die("Select Error: ".mysql_error());

$result = mysql_query("INSERT INTO Students (firstName, lastName, school, event, gender) VALUES ('$firstname','$lastname','$school','$events','$gender')") or die ("Insert Error: ".mysql_error());

mysql_close($link);
?>

your .fla can be downloaded from

http://www.freewebs.com/seandelaneydownloads/nejimmy.zip

if any problems post them here

Sean
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 2000 total points
ID: 13565138
Well what do you think?
0
 

Author Comment

by:nejimmy
ID: 13569041
OK now that I'm done with all my "Did you reboot?" duties and have had time to test a couple things:
1. The file in the zip was Flash MX 2004 not MX so I couldn't open it, so I downloaded the trial and converted it back to MX
2. In form.php there was one space of white space and it was tellin'me the database wasn't correct, eventually found it.
3. I learned a lot and your code was easy to follow and Eureka it works! Thanks man really appreciate it.

I'm including the action script and the php code so as to assist anyone else who might find it helpful to see code with variables included like I do.

//form.php

<?php

$school = $_POST['school_cb'];
$events = $_POST['events_cb'];
$gender = $_POST['gender_cb'];
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];

$db = "entries";

$link = mysql_connect("10.40.4.160","root","");

if (!$link)
      die ("Couldn't connect to MySQL");

mysql_select_db($db , $link) or die("Select Error: ".mysql_error());

$result = mysql_query("INSERT INTO students (firstName, lastName, school, event, gender)
VALUES ('$firstname','$lastname','$school','$events','$gender')") or die ("Insert Error: ".mysql_error());

mysql_close($link);
?>

//actionscript for submit button

on(press, keyPress "<Enter>") {
     if (school.getSelectedIndex() == 0 || events.getSelectedIndex() == 0 || gender.getSelectedIndex() == 0 || !firstName.length || !lastName.length){
          getURL("javascript:alert('Some required fields are still empty!');void(0)");
     } else {
          // ADDED HERE
          var data_var = new LoadVars();
          data_var.onLoad = function(success){
               if(success){
                    getURL("javascript:alert('" + this.message + "');void(0)");
               } else {
                    getURL("javascript:alert('cannot find my form!');void(0)");
               }
          };
          data_var.school_cb = school.getSelectedItem().data;
          data_var.events_cb = events.getSelectedItem().data;
          data_var.gender_cb = gender.getSelectedItem().data;
          // ATTENTION HERE, MAYBE THERE WAS AN ERROR
          data_var.fname = firstName.text;
          data_var.lname = lastName.text;
          data_var.sendAndLoad("form.php", data_var, "POST");
          getURL("javascript:alert('Thank you for submitting your details');void(0)");
          school.setSelectedIndex(0);
          events.setSelectedIndex(0);
          gender.setSelectedIndex(0);
          // USE .TEXT PROPERTY
          firstName.text = "";
          lastName.text = "";
     }
}


Thanks again Sean Happy St. Patty's Day dude :)--[__]
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 13572712
<<< 1. The file in the zip was Flash MX 2004 not MX so I couldn't open it, so I downloaded the trial and converted it back to MX

oh i wasnt aware that MX & MX2004 didnt work together...
sorry

what was the one space of white?

<<< 2. In form.php there was one space of white space and it was tellin'me the database wasn't correct, eventually found it.

ya i get the same problems in our office. im a systems administrator and some of the problems are soooooo stu*id
anyways hopoe i can help again sometime...

Regards
Sean

go raibh míle maith agat [thank you very much]

p.s im Irish!
0
 

Author Comment

by:nejimmy
ID: 13591603
Yea you can open MX in MXPro or MXPro2004 but not the other way-
In form.php line 9 it reads $db = "Entries "; -when I got rid of the white space it worked-
ps My last name is Nolan-I'm ½Dutch ½Irish-
again thanks from Nebraska-GO BIG RED (local college football and statewide chant)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question