Jump to content

check already registered query


fife

Recommended Posts

Hi.  I have wrote a simple login script.  Works perfectly.  Now as my users can only register one email address at the minute if you register two the same you get the default sql error pop up.  I want my own error so at the beginning of my script i wrote the following code. however.  It does not seem to be running.  It does not create an error but still allows duplicate emails in the database.  can anyone see the error of my ways?

<?php session_start();
if(isset($_POST['create'])){    
//script for checking if the email account already exists
$qCheckEmail = "SELECT * FROM members WHERE email='".$_POST['email']."'";
$rCheckEmail = mysql_query($qCheckEmail);
$Email = mysql_fetch_array($rCheckEmail);

if($_POST['email'] == $Email['email']) 
{$emailDup = "This email account has already been registered";}
else
{ 
//Process data for validation    
$forename	= 	trim($_POST['forename']);    
$surname	= 	trim($_POST['surname']);    
$email      = 	trim($_POST['email']);        
$password   = 	trim($_POST['password']);     
$gender     = 	trim($_POST['gender']);
$birthday	= 	$_POST['birthday'];
$creationdate = $_POST['creationdate'];
$validationID = $_POST['validationID'];
$accesslevel = 	trim($_POST['accesslevel']);
$accountType =  trim($_POST['accountType']);
// then the rest of the login script here

Link to comment
https://forums.phpfreaks.com/topic/216710-check-already-registered-query/
Share on other sites

Try something like...

 

...
$qCheckEmail = "SELECT * FROM members WHERE email='".$_POST['email']."'";
$rCheckEmail = mysql_query($qCheckEmail);
if(mysql_num_rows($rCheckEmail)>=1){
// already at least one entry, so it's already registered, tell 'em about it!
}
else
{
// no entries, so carry on with reg...
}
...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.