Jump to content

Recommended Posts

Hi, i am developing a website that allows users to log in, create accounts, and manage accounts. I am storing the users in a database table. Then I am using php to let them do the things i mentioned. Everything works great but I need a way of checking the database and making sure that if someone creates an account, it does not have the same information as another one in the table.

 

So if someone creates an account called Bob, i dont want someone else creating an account with the name Bob. Just seems like a lot of problems will pop up with that. Is there a way to check?

 

I am using a createAccount.php page that holds the form. Then I have a processCreate.php that handles adding the information so I guess i would need the processCreate updated to add this code.

 

Here is the process Create:

 

<?php
//Store variables the users choices from index page:
$namechoice=$_GET['userName'];
$passchoice=$_GET['userPass'];
$question=$_GET['userQuest'];
$answer=$_GET['userQuestAnswer'];
$email=$_GET['userEmail'];
$emailCheck=$_GET['userEmailCheck'];



//Switch statement to retrieve the correct security question that was sent over and sets a variable to the correct text
switch($question){
	case '1' :
		$userQuestion = "What is your first pet's name?";
		break;
	case '2' :
		$userQuestion = "Where is your home town?";
		break;
	case '3' :
		$userQuestion = "What is your mother's maiden name?";
		break;
	case '4' :
		$userQuestion = "Where did you go to high school?";
	default:
		$userQuestion = "What is your first pet's name?";
}


//----------------------------Validation--------------------------------
//Note: Need to make it so that it checks the name in the database and make sure it doesnt exist
//if name field blank
if($namechoice==""){
//redirect the browser back to createaccount.php if wrong
header("Location:createaccount.php?error=noname");
}
//if password field blank
elseif($passchoice==""){
header("Location:createaccount.php?error=nopassword");
}
//if answer field blank
elseif($answer==""){
header("Location:createaccount.php?error=noanswer");
}
//if emailcheck field blank
elseif($emailCheck==""){
header("Location:createaccount.php?error=noemailcheck");
}
//if email field blank
elseif($email==""){
header("Location:createaccount.php?error=noemail");
} 
//if email does not match
elseif($email != $emailCheck){
	header("Location:createaccount.php?error=nomatch");
}else{

//------------------------End Validation------------------------------


//Make a connection to the server... connect("servername","username","password") (or die is optional to show error)
$link=mysql_connect("localhost","tyzangme_tyler","*****") or die("No server connection".mysql_error());

//connect to our database
$db=mysql_select_db("tyzangme_clickndine") or die("No Database Connection ".mysql_error());

//construct a SQL query that selects users from DB
$query="INSERT INTO clientTable VALUES (NULL,\"$namechoice\",\"$passchoice\",\"normal\",\"$userQuestion\",\"$answer\",\"$email\");";

//run the query
$result=mysql_query($query);


//close the connection
mysql_close($link);

//redirect the browser back to index with string that activates message
header("Location:createconfirm.php");

}

?>

Link to comment
https://forums.phpfreaks.com/topic/141464-solved-does-it-exist-already/
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.