473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Don't write / duplicate email if it already exists

1 New Member
I have used some software (Forms To Go) to make a PHP script that writes to a mySQL database (I am collecting names and emails for newsletters).

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
  1. if ( $FTGnewsletter == "newsletterY" ) {
  2.  
  3. // the above is the part that only runs the following if Y box is checked
  4.  
  5. // below is all by FTG apart from the email check code
  6.  
  7. #====================================================
  8. # Dump field values to a MySQL table                =
  9. #====================================================
  10.  
  11.  
  12.  
  13. $mysql_link = @mysql_connect("mysql2.address.com", "username", "password");
  14.  
  15. if (mysql_errno() > 0) {
  16.    echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
  17.    exit;
  18. }
  19.  
  20. if (mysql_errno() == 0) {
  21.  
  22.  @mysql_select_db("database_name", $mysql_link);
  23.  
  24.  if (mysql_errno() > 0) {
  25.     echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
  26.     exit;
  27.  }
  28.  
  29. }
  30.  
  31. // i have added email check code here
  32.  
  33. if (!in_array ($FTG_sendersemail, $FTG_sendersemail)) {
  34. $FTG_sendersemail[] =$FTG_sendersemail;
  35.  
  36. # Redirect user to success page
  37.  
  38. header("Location: confirmation.htm");
  39.  
  40. }
  41.  
  42. else   
  43.  
  44. // this is the end of the email check code
  45.  
  46. if (get_magic_quotes_gpc()) {
  47.  $FTG__sendersname = stripslashes($FTG_sendersname);
  48.  $FTG__sendersemail = stripslashes($FTG_sendersemail);
  49. } else {
  50.  $FTG__sendersname = $FTG_sendersname;
  51.  $FTG__sendersemail = $FTG_sendersemail;
  52. }
  53.  
  54. if (mysql_errno() == 0) {
  55.  
  56.  $sqlcmd = sprintf("INSERT INTO `nws_ltter`(`_sendersname`, `_sendersemail`) VALUES('%s', '%s')",
  57.                    mysql_real_escape_string($FTG__sendersname, $mysql_link),
  58.                    mysql_real_escape_string($FTG__sendersemail, $mysql_link));
  59.  
  60.  @mysql_query($sqlcmd, $mysql_link);
  61.  
  62.  if (mysql_errno() > 0) {
  63.     echo 'MySQL error # ' . mysql_errno() . ' : ' . mysql_error() . '<br>';
  64.     exit;
  65.  }
  66.  
  67. }
  68.  
  69. } // this is the end of the newsletterY code 
Oct 16 '07 #1
1 1883
hawkenterprises
10 New Member
Why not just search for a contact or newsletter script? It's much easier to drive your car to work instead of trying to build a new car.
Oct 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2994
by: JStrummer | last post by:
I just put together a PHP mailing list sign-up page that posts to a mySQL DB. The PHP script prevents INSERTs when the email address is already located in the database. Problem: I need to import some flat-files that stored the signups, prior to this new form. Email addresses weren't checked, so there are a lot of records that have the same email address. Once I import these into the table, how would I go about putting together a SQL...
2
6089
by: John Steen | last post by:
This is probably a silly question to most of you, but I'm in the process of splitting off years from a large DB to several smaller ones. Some of the existing smaller DBs already have most of the data for their respective years. But some of the same data is also on the source DB. If I simply do an insert keying on the year column, and a row being inserted from the source DB already exists in the target DB, will a duplicate row be...
8
9497
by: Nick | last post by:
I have a table with columns (product_id,related_product_id,related_counter) If product A is related to product B then a record should be created, if the record already exists then the related_counter should be incremented. This is very easy to do with MySQL using INSERT... ON DUPLICATE KEY. Standard or not, it is very usefull.
24
19916
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every renewal in the history of the policyholder. The information is in 2 tables, policy and customer, which share the custid data. The polno changes with every renewal Renewals in 2004 would be D, 2005 S, and 2006 L. polexpdates for a given customer...
0
789
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14059
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
4047
by: audj | last post by:
Hello, I am trying to use a subquery to avoid duplicate entries when someone submits a form to subscribe to a mailing list. So I want to check if the email exists before adding the record. I tried something like: INSERT INTO mailing_list (ID,Email) VALUES ('','$Email') WHERE NOT EXISTS (SELECT * FROM mailing_list WHERE Email LIKE '$Email'') Using NOT IN and various other structures, but keep receiving mysql errors.
2
2782
by: =?Utf-8?B?ZG90cHJvMjAwOA==?= | last post by:
In ASP.NET 2.0 project, I have added a dataset and have setup the datatable and configured the datatableadapter (using the wizards). In my code I can use the mytableadapter.insert method to insert a new record in the table. How do I check if the key column value being inserted this time already exists and hence prompt the user the message ("userid already exists" or "email address already exists")
36
2911
by: ashenton | last post by:
Hi, I have a stock database and have recently solved an issue with duplication. When a user enters a duplicate value in the 'DAMS_Number' field on a form, a message box alerts the user that the value already exists. What I would like is for the form to display the corresponding record as soon as the user clicks 'Ok' on the message box. The code I have for the duplicate alert (which I obtained from this site btw!) is as follows:
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.