Current location: Hot Scripts Forums » Programming Languages » PHP » Interesting


Interesting

Reply
  #1 (permalink)  
Old 01-24-04, 01:01 AM
Merovingian's Avatar
Merovingian Merovingian is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Los Angeles
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Interesting

Does anyone know how to check if a database holds an e-mail address , so that a user that signs up for a newsletter doesnt add the same email twice to the database, and if so an error statement for the e-mail address in the database can be echoed unto the page so the user can see that their e-mail address is already in the database.
__________________
"Duo seguere aut de via decede" ...
Reply With Quote
  #2 (permalink)  
Old 01-24-04, 05:10 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
there are 2 methods to achive this .
one is to make the 'email' field in the database as a unique index , so if someone tried to add the same email, mysql will generate a 'duplicated entry' error ..
the other way is to check upon the provied mail address by useing a SELECT query which will check, mysql_num_rows() gave a number > 0 , you generate the error :
PHP Code:

$provided_email=trim($_POST['email']);//this will get the email from a from using POST method..


$check=mysql_query("SELECT email FROM table_1 WHERE email='$provided_email'")or
die(
mysql_error());

$num=mysql_num_rows($check);

if ( 
$num ) {
 echo
'E-mail address you provided is already in database !';
 die();
} else {
//COMPLETE SCRIPT HERE..

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 01-24-04 at 05:15 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Rules Merovingian PHP 10 01-15-04 11:52 AM


All times are GMT -5. The time now is 07:56 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.