• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 782
  • Last Modified:

flash mx form insert data into mysql using php

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
nejimmy
Asked:
nejimmy
  • 22
  • 12
1 Solution
 
ellandrdCommented:
ok first of all, can you program in php/mysql/flash?
0
 
ellandrdCommented:
what you are trying to do is very easy

what version of flash are you using?
0
 
ellandrdCommented:
post your .fla, you php scripts etc.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ellandrdCommented:
your*
0
 
ellandrdCommented:
<<<< 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
 
ellandrdCommented:
BTW

Welcome to Experts-Exchange!
0
 
nejimmyAuthor Commented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
p.s have you ever used MySQL before and have you mysql set up on your machine or server?
0
 
nejimmyAuthor Commented:
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
 
nejimmyAuthor Commented:
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
 
nejimmyAuthor Commented:
Stupid 504 timeout sorry for double post
0
 
ellandrdCommented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
when the user clicks submit, where do you want to bring the user next or what do you want happening next?
0
 
nejimmyAuthor Commented:
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
 
nejimmyAuthor Commented:
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
 
ellandrdCommented:
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
 
nejimmyAuthor Commented:
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
 
ellandrdCommented:
ok, i'll let you decide what you wnat to do after form is submitted. for now i direct them to another frame...
0
 
nejimmyAuthor Commented:
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
 
ellandrdCommented:
can you post your database name and the name of the table you are inserting the student details into
0
 
nejimmyAuthor Commented:
database name = Entries
table name = Students
and then I basically am filling 5 fields (firstName, lastName, school, event, gender)
0
 
ellandrdCommented:
sorry for the time gaps of posts.

im in europe and i take it your in the states
0
 
nejimmyAuthor Commented:
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
 
ellandrdCommented:
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
 
ellandrdCommented:
Well what do you think?
0
 
nejimmyAuthor Commented:
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
 
ellandrdCommented:
<<< 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
 
nejimmyAuthor Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 22
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now