Current location: Hot Scripts Forums » Programming Languages » PHP » PHP email validation using a MYSQL database list


PHP email validation using a MYSQL database list

Reply
  #1 (permalink)  
Old 04-06-10, 12:13 PM
noobCoder noobCoder is offline
New Member
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Spin PHP email validation using a MYSQL database list

i am creating a register page for my website and i wish to create some kind of validation upon the email box so that only people with a valid domain can become a member and then use my website.

So only people with domains such as @bathspa.ac.uk etc... can join the site.

So i have created my database table to contain the domain names of all the universities within the UK and the table is called 'domain' and the feilds are called 'domain_id' to uniqely identify each domain with the table and 'domain_name' which contains the domain extension such as @bathspa.co.uk.

now i have looked at scripts on the internet and i dont want to use javascript due to personal development reasons, so i am looking to use a PHP script.

I was unsure how to start but i have found some code below which i understands checks if a email is correct but i wish to check the second part of the string after the '@' against the list in my database table.

PHP Code:

<?php
if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$email)) 
{
   return 
FALSE;
}
?>
if anyone could help ASAP i would be most grateful

Kind Regards

noobCoder

Last edited by job0107; 04-08-10 at 09:12 PM.
Reply With Quote
  #2 (permalink)  
Old 04-06-10, 01:10 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
You might want to check out some of the existing scripts.

Search Listings | Hot Scripts

You may choose to use them or just learn from some of them.
Reply With Quote
  #3 (permalink)  
Old 04-06-10, 03:53 PM
vitro012 vitro012 is offline
New Member
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[QUOTE=noobCoder;187923]i am creating a register page for my website and i wish to create some kind of validation upon the email box so that only people with a valid domain can become a member and then use my website.

So only people with domains such as @bathspa.ac.uk etc... can join the site.

So i have created my database table to contain the domain names of all the universities within the UK and the table is called 'domain' and the feilds are called 'domain_id' to uniqely identify each domain with the table and 'domain_name' which contains the domain extension such as @bathspa.co.uk.

now i have looked at scripts on the internet and i dont want to use javascript due to personal development reasons, so i am looking to use a PHP script.

I was unsure how to start but i have found some code below which i understands checks if a email is correct but i wish to check the second part of the string after the '@' against the list in my database table.


<?php
if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))

************************************************** **************************************************

eregi is precated

you can use:

if (!preg_match('/^[^0-9][a-zA-Z0-9_]+[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',$correo))
{
return $msj="incorrect mail ";
}else
{
return $msj= "well done";
}




Saludos
Reply With Quote
  #4 (permalink)  
Old 04-07-10, 10:14 AM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:

<?php
 
////////////////////////////
 /////DB connection///
 // ******** EDIT CONNECTION INFORMATION BELOW  ************

$hostname "localhost";
$database "ptalk";
$username "root";
$password "";


// *********** END EDIT CONNECTION INFORMATION ************
$con mysql_connect($hostname$username$password);
mysql_select_db($database$con);

$sql "SELECT `domain_name` FROM `domain`";
$result mysql_query($sql);
if(
mysql_num_rows($result) > 0) {
    while(
$r mysql_fetch_row($result)) {
        
$domains[] = str_replace('@','',$r[0]);
    }
}
else {
    
$domains = array();
}
/////////End DB interaction//////////////////

/////////Start form interaction//////////////

//Get form variables
$email = (isset($_POST['email'])) ? $_POST['email'] : 1.1;

//Split out the domain.
$email_domain = ($email != 1.1) ? explode('@',$email) : '@nowhere.com';

//email matching pattern.
$pattern '/^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/';

if(!
preg_match($pattern,$email)) { //If email doesn't match the pattern.
    
echo 'You have entered an incorrectly formatted email address.';
}
elseif(!
in_array($email_domain[0],$domains)) { //If the domain doesn't exist in the database array.
    
echo 'You\'re email isn\'t registered with our site!';
}
else {
    
//Do all the registration stuff.
}

?>
Reply With Quote
  #5 (permalink)  
Old 04-12-10, 06:02 AM
noobCoder noobCoder is offline
New Member
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi people thank you for the feedback, i manged to get the solution from Jcbones help and my friends help
Reply With Quote
Reply

Bookmarks

Tags
email validation, mysql problems, php, php mysql phpmyadmin, validation help


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
Drop down list in PHP and Mysql kubik PHP 11 02-26-07 06:10 AM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 12-16-05 08:15 AM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 01-30-05 10:51 PM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-30-04 01:19 PM


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