Jump to content

Checking if a username has been used twice


frank_solo

Recommended Posts

I have written the code for email check, but how and where can I put the code to check if a username has been used twice? Thanks in advance.

<?php

$servername	= "localhost";
$username	= "";
$password	= "";

//validate fields
if(!$_POST["username"] || !$_POST["email"] || !$_POST["password1"] || !$_POST["password2"]){
	echo "<p> </p><p> </p><p> </p><br />Please fill the required fields, <p> </p><p> </p><a href='register.php'>Go to register page</a>";

//validate password
}else if($_POST["password1"] != $_POST["password2"]){
	echo "<p> </p><p> </p><p> </p><br />Please go back, PASSWORDS do not match! <p> </p><p> </p><a href='register.php'>Go to register page</a>";

//validate email	
}else if(!(eregi("^.+@.+\\..+$", $_POST['email']))){	
	echo "<p> </p><p> </p><p> </p><br />Please enter a valid EMAIL! <a href='register.php'><p> </p><p> </p>Go to register page</a>";

//validate captcha
}else if(($_SESSION['security_code'] != $_POST['security_code']) || (empty($_SESSION['security_code'])) ){
	echo "<p> </p><p> </p><p> </p><br />CAPTCHA CODE does not match! <p> </p><p> </p><a href='register.php'>Go to register page</a>";

}else{
	$conn=  mysql_connect($servername,$username,$password)or die(mysql_error());
	mysql_select_db("genesis_members",$conn);

	// check if already registered
	$sql_check = "SELECT * FROM users WHERE email = '".$_POST[email]."'";
	$result_check = mysql_query($sql_check,$conn) or die(mysql_error());		
	$row = mysql_fetch_assoc($result_check);
	if($row['id']){
		echo "<p> </p><p> </p><p> </p><br />EMAIL already registered! <p> </p><p> </p><a href='register.php'>Go to register page</a>";
	}else{

		// insert in db
		$sql = "INSERT INTO users (username, email, password, company, phone, services) VALUES ('".$_POST[username]."', '".$_POST[email]."', '".$_POST[password1]."', '".$_POST[company]."', '".$_POST[phone]."', '".$_POST[services]."')";
		$result = mysql_query($sql,$conn) or die(mysql_error());

		echo "<p> </p><p> </p><p> </p><br /><h1>You Have Successfully Registered</h1>";
		echo "<p> </p><p> </p><br /><a href='main_login.php'>go to login page</a>";
	}
}		

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.