473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Don't write / duplicate email if it already exists

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 1862
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
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...
2
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...
8
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...
24
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...
0
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...
3
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...
3
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. ...
2
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...
36
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.