zang8027 Posted January 19, 2009 Share Posted January 19, 2009 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141464-solved-does-it-exist-already/ Share on other sites More sharing options...
MadTechie Posted January 19, 2009 Share Posted January 19, 2009 Just check to see if it exists $query ="SELECT count(`name`) as found FROM Users WHERE name='bob' "; if($ROW['found'] > 0) { echo "already in use!"; } the above is just to give you the idea and is not working code! Quote Link to comment https://forums.phpfreaks.com/topic/141464-solved-does-it-exist-already/#findComment-740463 Share on other sites More sharing options...
revraz Posted January 19, 2009 Share Posted January 19, 2009 Here is a checkunique function I posted awhile back. http://www.phpfreaks.com/forums/index.php/topic,202729.msg917595.html#msg917595 Quote Link to comment https://forums.phpfreaks.com/topic/141464-solved-does-it-exist-already/#findComment-740464 Share on other sites More sharing options...
zang8027 Posted January 19, 2009 Author Share Posted January 19, 2009 thanks for showing me that topic! worked great Quote Link to comment https://forums.phpfreaks.com/topic/141464-solved-does-it-exist-already/#findComment-740475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.