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
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.
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!";
?>
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?
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.