View Full Version : flash/php mailing list
zerosignal0
October 2nd, 2004, 02:42 AM
Hello,
I am trying to make a flash mailing list submitter that will allow the user to input their name and email address to be added to a sql database that I have setup. I understand an ok ammount about using php with mysql but I just cant figure out for the life of me what the actual php script would be.... I have 2 input text fields , name and email that they fill in.. can anyone help me out with coding what the php would be? I am starting to grasp the integration between the 2 and i think with just a little more help I wont have to ask to many questions anymore ;)
thanks in advance
Digitalosophy
October 2nd, 2004, 03:52 AM
here's an example of a form i just did, that submits to mysql db.
Note: if you search you'll get a better explanation.
<?
include("../dbConfig.php");
$username = $_POST["username"];
$password = $_POST["password"];
$company = $_POST["company"];
$person = $_POST["person"];
$email = $_POST["email"];
$phone = $_POST["phone"];
//insert the values
$result= MYSQL_QUERY("INSERT INTO users (userID, userName, userPassword, userEmail, userCompany, userPerson, userPhone)".
"VALUES ('NULL', '$username', '$password', '$email', '$company','$person', '$phone')");
?>
to understand the SQL go to http://www.w3schools.com/sql/sql_insert.asp
other then that just make a database connection file, and change the variable, table, and field names.
edit: Try to understand the logic, once you know what you have to do, you can always look up a reference.
For example...
In this case, we need to:
1.connect to the database
2.capture the variables
3.insert the data.
of course to send the data from flash you would want to use LoadVars(). once you get the data outside of flash, the php is the same as if the form were made in HTML.
zerosignal0
October 2nd, 2004, 06:38 AM
thanks for the help!
I figured it out! ;)
Im really happy because this is the first full php/sql/flash intergration that Ive written completly on my own so its a pretty big feat for me.
Now heres a question that I cant quite seem to figure out... what do you think would be a good if statement that would check to see if that person has already signed up for the mailing?
heres the code Ive got
<?
$name=$_POST['name'];
$email=$_POST['email'];
//connect to database
mysql_pconnect("mysql9.secureserver.net","mailist","list") or die ("didn't connect to mysql");
mysql_select_db("mailist") or die ("no database");
//make query
$query = "INSERT INTO maillist (email) VALUES (email)";
$query = "INSERT INTO maillist (name) VALUES (name)";
//prints back to flash textbox
print "status1=Added to mailing list!";
?>
zerosignal0
October 2nd, 2004, 07:33 AM
ok well heres the code that I have come up with so far
<?
//this pulls the variables from the flash movie when the user
//hits submit. Use this when your global variables are off.
//I don't know how to toggle global variables, so I just put
//it in all the time ;)
$name=$_POST['name'];
$email=$_POST['email'];
//connect to database
mysql_pconnect("mysql9.secureserver.net","mailist","list") or die ("didn't connect to mysql");
mysql_select_db("mailist") or die ("no database");
//make query
$query = "INSERT INTO maillist (email) VALUES ($email)";
$query = "INSERT INTO maillist (name) VALUES ($name)";
//see if there's an EXACT match
print "status1=Added to mailing list!";
?>
everything seems fine through flash but I dont think that php is sending the vaiables to sql....
also how can I go about modding what I have to check to see if the person is already in the database and if they are to show that they are in the text box within flash? I know its going to be an if statement but what kind of if statement?
Digitalosophy
October 2nd, 2004, 12:24 PM
$query = "INSERT INTO maillist (name, email) VALUES ('$name','$email')";
trynhg to find a good link for your second question, that will explain it well..
zerosignal0
October 2nd, 2004, 03:24 PM
sweet thanks so much dig I really appriciate the help!! ;)
hope your able to find something for the second part because I still havent had any luck.
Digitalosophy
October 2nd, 2004, 03:37 PM
no prob ;)
zerosignal0
October 2nd, 2004, 07:06 PM
any luck at finding a tut on how to verify if the person has already signed up?
Digitalosophy
October 2nd, 2004, 07:38 PM
I actually didn't find to many but this should help.
http://devmafia.com/article.php?aid=40
Bascially you have to make an additional SQL query to select all the users from the database. If the username that was submitted does not match any username's in the database then proceed to insert your data.
If not print an error message
zerosignal0
October 3rd, 2004, 12:37 AM
well thanks again that pushed me into the right direction and now it works!
thanks
Digitalosophy
October 3rd, 2004, 03:39 AM
cool, your welcome
lbeetles
October 4th, 2004, 12:04 PM
Hi i am trying to do this, would you be able to point me in the right direction with the loadVars bit because for some reason i just can't seem to get it to work.
Digitalosophy
October 4th, 2004, 12:08 PM
http://www.flash-db.com/Tutorials/saving/
lbeetles
October 4th, 2004, 12:09 PM
cheers Digitalosophy and thanks for the quick reply.
Digitalosophy
October 4th, 2004, 12:22 PM
np, if you have troubles just repost ;)
lbeetles
October 4th, 2004, 12:40 PM
I have managed to get it working now, so it goes into my mysql db. Now ive just gota look into the verify side of it so i don't get duplicates in my mailinglist. I shall check yr link out that you posted. Any hints on it thou of what to look out for???
Digitalosophy
October 4th, 2004, 12:47 PM
Well for that you'd be doing the same thing zerosignal was doing, only you'll have to use
sendAndLoad();
to tell flash if the record has already been submitted. Same concept, just now instead of printing the error message on a php page, you'll be doing the same thing, only printing it in Flash.
Remeber, Flash doesn't accept variables unless it is in this form
The first thing you need to know about Flash is the method in which it handles variables from remote files. Flash will take an URL-encoded query string and transform it into a list of variables within its own memory. An example of a string that Flash recognizes as variable definitions looks like this:
size=Medium&color=Navy+Blue&style=Mandarin+Collar
http://www.asp101.com/articles/flash/index.asp
even though it's ASP its still the same concept.
lbeetles
October 4th, 2004, 12:50 PM
cheers i shall get stuck into this and see what i come up with. thanks for your help.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.