nejimmy
asked on
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
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
ok first of all, can you program in php/mysql/flash?
what you are trying to do is very easy
what version of flash are you using?
what version of flash are you using?
post your .fla, you php scripts etc.
your*
<<<< 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?
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?
BTW
Welcome to Experts-Exchange!
Welcome to Experts-Exchange!
ASKER
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
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_passw ord");
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_3r d_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
<?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","
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_
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
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.
you cannot upload your .fla on EE and post the URL here.
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
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
p.s have you ever used MySQL before and have you mysql set up on your machine or server?
ASKER
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
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
ASKER
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
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
ASKER
Stupid 504 timeout sorry for double post
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...
i will download you .fla now
PHP is hard to learn, even though i learned it by University...
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...
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...
since your using flash mx, some good advice is to use the flash mx form component as it makes your site look for professional...
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...
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...
when the user clicks submit, where do you want to bring the user next or what do you want happening next?
ASKER
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?
ASKER
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.
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?
ok so after the user clicks submit what do you want happening? redirect to another page or stay in flash?
ASKER
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.
ok, i'll let you decide what you wnat to do after form is submitted. for now i direct them to another frame...
ASKER
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. [:{)
can you post your database name and the name of the table you are inserting the student details into
ASKER
database name = Entries
table name = Students
and then I basically am filling 5 fields (firstName, lastName, school, event, gender)
table name = Students
and then I basically am filling 5 fields (firstName, lastName, school, event, gender)
sorry for the time gaps of posts.
im in europe and i take it your in the states
im in europe and i take it your in the states
ASKER
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
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
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
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',
mysql_close($link);
?>
your .fla can be downloaded from
http://www.freewebs.com/seandelaneydownloads/nejimmy.zip
if any problems post them here
Sean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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().d ata;
data_var.events_cb = events.getSelectedItem().d ata;
data_var.gender_cb = gender.getSelectedItem().d ata;
// 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 :)--[__]
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
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',
mysql_close($link);
?>
//actionscript for submit button
on(press, keyPress "<Enter>") {
if (school.getSelectedIndex()
getURL("javascript:alert('
} else {
// ADDED HERE
var data_var = new LoadVars();
data_var.onLoad = function(success){
if(success){
getURL("javascript:alert('
} else {
getURL("javascript:alert('
}
};
data_var.school_cb = school.getSelectedItem().d
data_var.events_cb = events.getSelectedItem().d
data_var.gender_cb = gender.getSelectedItem().d
// ATTENTION HERE, MAYBE THERE WAS AN ERROR
data_var.fname = firstName.text;
data_var.lname = lastName.text;
data_var.sendAndLoad("form
getURL("javascript:alert('
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 :)--[__]
<<< 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!
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!
ASKER
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)
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)