Predd0 Posted July 30, 2004 Posted July 30, 2004 What I have set up on my oscommerce website is an external newsletter program (ListMessenger). This program grabs a list of email addresses from an SQL table. I have put an email capture on my website so someone can goto the main page, type in their email address, press submit and it adds their email address into the table. Heres the problem. In the SQL table, ListMessenger requires every email address to have a unique ID number. This is an auto-assigned integer. So if someone enters in [email protected] a first time it will go into the table with an ID of 1 (say). If they enter it in a second time (by accident) it will go in with an ID of 2. Therefore there are two entries for [email protected] and thus when I send out the newsletter, they will receive it twice. What I want to do is get this script to check if that email address already exists in the database. If it does, an error message to come back saying 'you are already subscribed'. Would anyone know the PHP code to do this? Thanks for any help in advance! Jay TNT Road Express based on post code contribution Orders in Holding 3.1
John Doswell Posted July 30, 2004 Posted July 30, 2004 you will find parts of code in create account i guess, that you could strip down and use. john
ryanf Posted July 30, 2004 Posted July 30, 2004 run a query like total = select count from yourtable where email = newemail; then if(total == 0) { add it } else { echo "Try again, email already exists"; } Ryan If I was crafty, this would be a funny signature.
Predd0 Posted July 31, 2004 Author Posted July 31, 2004 Thanks guys! I used a combination of both answers to get the desired outcome. Here's the code I used: } else { $check_email_query = tep_db_query("select count(*) as total from " . TABLE_NEWSLETTER . " where user_address = '" . tep_db_input($list_email_add) . "'"); $check_email = tep_db_fetch_array($check_email_query); if ($check_email['total'] > 0) { echo "<b>Your email already exists on our list!</b>"; } else { $q_type = "insert"; store_data( $list_firstname, $list_lastname, $list_email_add, $list_on_off, $q_type ); print "<p align=\"center\"><font face=\"verdana\"><b>Thank You! Your email address has been added to our newsletter list</b></font></p>"; } } } Jay TNT Road Express based on post code contribution Orders in Holding 3.1
John Doswell Posted August 2, 2004 Posted August 2, 2004 :D that`s what you call learning by doing.... well done ;) john
Recommended Posts
Archived
This topic is now archived and is closed to further replies.