I have customised it so that it only writes to the database if the Y box is checked and now I want it to only add the email address if it isn't already present BUT I still want the user to be redirected to a confirmation page AND for me to get an email confirming their name & email.
I have added a piece of script to try and check for existing email address using in_array but I really don't know what i am doing so any help would be appreciated.
Here is the script
Expand|Select|Wrap|Line Numbers
- if ( $FTGnewsletter == "newsletterY" ) {
- // the above is the part that only runs the following if Y box is checked
- // below is all by FTG apart from the email check code
- #====================================================
- # Dump field values to a MySQL table =
- #====================================================
- $mysql_link = @mysql_connect("mysql2.address.com", "username", "password");
- if (mysql_errno() > 0) {
- echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
- exit;
- }
- if (mysql_errno() == 0) {
- @mysql_select_db("database_name", $mysql_link);
- if (mysql_errno() > 0) {
- echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
- exit;
- }
- }
- // i have added email check code here
- if (!in_array ($FTG_sendersemail, $FTG_sendersemail)) {
- $FTG_sendersemail[] =$FTG_sendersemail;
- # Redirect user to success page
- header("Location: confirmation.htm");
- }
- else
- // this is the end of the email check code
- if (get_magic_quotes_gpc()) {
- $FTG__sendersname = stripslashes($FTG_sendersname);
- $FTG__sendersemail = stripslashes($FTG_sendersemail);
- } else {
- $FTG__sendersname = $FTG_sendersname;
- $FTG__sendersemail = $FTG_sendersemail;
- }
- if (mysql_errno() == 0) {
- $sqlcmd = sprintf("INSERT INTO `nws_ltter`(`_sendersname`, `_sendersemail`) VALUES('%s', '%s')",
- mysql_real_escape_string($FTG__sendersname, $mysql_link),
- mysql_real_escape_string($FTG__sendersemail, $mysql_link));
- @mysql_query($sqlcmd, $mysql_link);
- if (mysql_errno() > 0) {
- echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
- exit;
- }
- }
- } // this is the end of the newsletterY code