Advertisement

06.28.2008 at 04:30PM PDT, ID: 23524420
[x]
Attachment Details

How to check for duplicate email address in database

Asked by polyprod in New Internet Users, MySQL

Hello,
I have a registration script, that works fine , but i want to modify it to check if the email has alredy been used in the data base., to prevent members from registering multiple accounts with the same email..
i have been trying for a week but cant get it to work , would be grateful for any help. Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
<?php
session_start();
header("Cache-control: private");
$dateRegistered=time();
$currentTime=date("YmdHis");
$userId=md5("$currentTime".$_SERVER['REMOTE_ADDR']);
 
if($_POST[UserName]!="" && $_POST[Password1]!="" && $_POST[Password2]!="" && $_POST[Email]!=""  && $_POST[Name] !="" && $_POST[Country] !="" && $_POST[State] !="" && $_POST[City] !=""&& $_POST[ZipCode] !="" && $_POST[Adress] !="" && $_POST[phone]!=""){
	$errorMsg="";
	include ("../dbase.php");
	include ("../settings.php");
 
	//check if we have a user with the same id
 
	$userExists=false;
	$replacevalues = array('&','/'," ","?","+","%","$","#","@");
	$username=str_replace($replacevalues,"", $_POST['UserName']);
	$result = mysql_query("SELECT user FROM chatusers WHERE user='$username'");
	
	if (mysql_num_rows($result)==1){
 
	$errorMsg="Username exists, please choose another one!";
 
	} else if($_POST[Password1]!=$_POST[Password2]) {
 
	$errorMsg="Passwords do not match";
 
	}else if(strlen($_POST[Password1])<6){
 
	$errorMsg="Passwords must be at least 6 characters long";
 
	}else{
	if(!mysql_query("INSERT INTO chatusers ( id , user , password , email , name , country , state , city, phone, zip , adress , dateRegistered,lastLogIn, emailnotify ,smsnotify,status,emailtype ) 
 
			VALUES ('$userId','$username', '$_POST[Password1]', '$_POST[Email]', '$_POST[Name]', '$_POST[Country]', '$_POST[State]','$_POST[City]','$_POST[phone]', '$_POST[ZipCode]', '$_POST[Adress]', '$dateRegistered', '$currentTime','0','0','pending','$_POST[emailtype]')"))
 
			{ 
 
			$errorMsg="Could not modify database";
 
			} else {
 
			}
 
	}
 
	mysql_free_result($result);
	if ($errorMsg==""){
 
	$subject = "Your account activation at $siteurl"; 
 
if ($_POST['emailtype']=="text"){
 
$charset="Content-type: text/plain; charset=iso-8859-1\r\n";
$message = "Thank you for registering at $siteurl 
In order to activate your newly created account copy and paste the link below in your browser:
 
$siteurl/actm.php?UID=$userId
 
Once you activate your membership you will recieve a mail with your login information.
Thanks!
 
The Webmaster
 
This is an automated response, please do not reply!";
 
} else if($_POST['emailtype']=="html"){
 
$charset="Content-type: text/html; charset=iso-8859-1\r\n";
$message = "Thank you for registering at $siteurl 
In order to activate your newly created account copy and paste the link below in your browser:<br><br>
 
<a href='$siteurl/actm.php?UID=$userId'>$siteurl/actm.php?UID=$userId</a><br><br>
 
Once you activate your membership you will recieve a mail with your login information.<br><br>
 
Thanks! <br>
 
The Webmaster <br>
This is an automated response, please do not reply!<br>";
}
mail($_POST['Email'], $subject, $message, "MIME-Version: 1.0\r\n".$charset."From:'$registrationemail'\r\nReply-To:'$registrationemail'\r\n"."X-Mailer:PHP/".phpversion() );
header ("Location: userregistered.php");
}
 
} 
else 
{
$errorMsg="Please fill all the required fields.";
}
?>
<?
include("_reg.header.php");
?>
<table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="52"><p><span class="big_title style8"><br>
      </span><span class="big_title">Member Registration Form</span><br>      
        <span class="small_title"> <span class="small_title">Become a Member and you'll be able to contact all of our expert VideoChat Models, chat with them (even in private 1 to 1), view select Models photos, Video recordings see some of the top Models in your favorites and get notified when they are online, get notified about special events and parties and more... AND YOU DON'T EVEN NEED A WEBCAM!!!</span><br> 
        </span><span class="small_title">
        <br>
        <span class="error">
        <?php if ( isset($errorMsg) && $errorMsg!=""){ echo $errorMsg; } ?>
        </span>
      </span></p>      </td>
  </tr>
</table>
<form action="user.php" method="post" enctype="multipart/form-data" name="form1" target="_self">
  <table width="720" border="0" align="center" cellpadding="4" cellspacing="0">
    <tr>
      <td class="barbg" height="16" colspan="3"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td class="form_header_title">Step 1: User Information </td>
        </tr>
      </table></td>
    </tr>
    <tr align="left" class="form_definitions">
      <td colspan="3">Login information. Your user will be a unique user.</td>
    </tr>
    <tr>
      <td width="160" align="right" class="form_definitions">
	  <? if(isset($_POST[UserName]) && $_POST[UserName]==""){
		  echo "<font color=#ffdd54>Username*</font>";
	 	 } else{
	 	 echo"Username";
	  }?>	  </td>
      <td><input name="UserName"  value="<? if (isset($_POST[UserName])){ echo $_POST[UserName]; }  ?>" type="text" id="UserName" size="24" maxlength="24"></td>
      <td width="310" class="form_informations">Your username will be visible to other in the text chat and in different parts of the site. Try to choose one that best represents you. </td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
	  <? if(isset($_POST[Password1]) && $_POST[Password1]==""){
		  echo "<font color=#ffdd54>Password*</font>";
	 	 } else{
	 	 echo"Password*";
	  }?>	  </td>
      <td><input name="Password1" type="password" id="Password1" size="24" maxlength="24"></td>
      <td class="form_informations">Minimum 6 characters </td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
	  <? if(isset($_POST[Password2]) && $_POST[Password2]==""){
		  echo "<font color=#ffdd54>Re-type the Password*</font>";
	 	 } else{
	 	 echo"Re-type the Password*";
	  }?>	  </td>
      <td><input name="Password2" type="password" id="Password2" size="24" maxlength="24"></td>
      <td>&npsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
	  <? if(isset($_POST[Email]) && $_POST[Email]==""){
		  echo "<font color=#ffdd54>E-mail*</font>";
	 	 } else{ echo"E-mail*";} 
	  ?>	  </td>
      <td><input name="Email" value="<? if (isset($_POST[Email])){ echo $_POST[Email]; }  ?>" type="text" id="Email" size="24" maxlength="24"></td>
      <td><span class="form_informations">Your email will not be visible to members and will not be discolsed to other parties. </span></td>
    </tr>
    <tr>
      <td align="right">&npsp;</td>
      <td>&npsp;</td>
      <td>&npsp;</td>
    </tr>
[+][-]06.28.2008 at 04:38PM PDT, ID: 21892382

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: New Internet Users, MySQL
Sign Up Now!
Solution Provided By: regnent
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.28.2008 at 04:40PM PDT, ID: 21892384

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 05:14PM PDT, ID: 21892473

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 05:42PM PDT, ID: 21892530

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 05:51PM PDT, ID: 21892554

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628