Added First and Last name fields and added INSERT for contacts table
This commit is contained in:
@@ -3,31 +3,36 @@
|
|||||||
unset($_SESSION['loggedInUser']);
|
unset($_SESSION['loggedInUser']);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if($_POST['signup_username'] != '' && $_POST['signup_password'] != ''){
|
if($_POST['signup_username'] != '' && $_POST['signup_fname'] != '' && $_POST['signup_lname'] != '' && $_POST['signup_password'] != ''){
|
||||||
// username and password must be 4 <= length <= 25
|
// username and password must be 4 <= length <= 25
|
||||||
if(4 <= strlen($_POST['signup_username']) && strlen($_POST['signup_username']) <= 25){
|
if(4 <= strlen($_POST['signup_username']) && strlen($_POST['signup_username']) <= 25){
|
||||||
if(4 <= strlen($_POST['signup_password']) && strlen($_POST['signup_password']) <= 25){
|
if(4 <= strlen($_POST['signup_password']) && strlen($_POST['signup_password']) <= 25){
|
||||||
// Make sure no special characters are present
|
if(1 <= strlen($_POST['signup_fname']) && strlen($_POST['signup_fname']) <= 25){
|
||||||
if(ctype_alnum($_POST['signup_username']) && ctype_alnum($_POST['signup_password'])){
|
if(1 <= strlen($_POST['signup_lname']) && strlen($_POST['signup_lname']) <= 25){
|
||||||
// Need to first check if a user with the desired username already esists
|
// Make sure no special characters are present
|
||||||
$db_check_statement = $db_connection->prepare("SELECT COUNT(*) FROM login WHERE username = '".$_POST["signup_username"]."'");
|
if(ctype_alnum($_POST['signup_username']) && ctype_alnum($_POST['signup_password'])){
|
||||||
$db_check_statement->execute();
|
// Need to first check if a user with the desired username already esists
|
||||||
$db_check_statement->setFetchMode(PDO::FETCH_ASSOC);
|
$db_check_statement = $db_connection->prepare("SELECT COUNT(*) FROM login WHERE username = '".$_POST["signup_username"]."'");
|
||||||
$db_check_returned = $db_check_statement->fetchAll();
|
$db_check_statement->execute();
|
||||||
$existingUsers = $db_check_returned[0]['COUNT(*)'];
|
$db_check_statement->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
if($existingUsers == 0){
|
$db_check_returned = $db_check_statement->fetchAll();
|
||||||
$db_connection->exec("INSERT INTO login (username, pword) VALUES ('".$_POST["signup_username"]."','".$_POST["signup_password"]."')");
|
$existingUsers = $db_check_returned[0]['COUNT(*)'];
|
||||||
$_SESSION["loginError"] = "Your account has been created and can now login";
|
if($existingUsers == 0){
|
||||||
unset($_SESSION['signupError']);
|
$db_connection->exec("INSERT INTO login (username, pword) VALUES ('".$_POST["signup_username"]."','".$_POST["signup_password"]."')");
|
||||||
header('Location: /login.php');
|
$db_connection->exec("INSERT INTO contacts (username, fname, lname) VALUES ('".$_POST["signup_username"]."','".$_POST["signup_fname"]."','".$_POST["signup_lname"]."')");
|
||||||
}else{$_SESSION["signupError"] = "Another user with that username already exists, please choose another name";}
|
$_SESSION["loginError"] = "Your account has been created and can now login";
|
||||||
}else{$_SESSION["signupError"] = "Special characters are not allowed";}
|
unset($_SESSION['signupError']);
|
||||||
|
header('Location: /login.php');
|
||||||
|
}else{$_SESSION["signupError"] = "Another user with that username already exists, please choose another name";}
|
||||||
|
}else{$_SESSION["signupError"] = "Special characters are not allowed";}
|
||||||
|
}else{$_SESSION["signupError"] = "Last Name must be at least 1 character and at most 25 characters";}
|
||||||
|
}else{$_SESSION["signupError"] = "First Name must be at least 1 character and at most 25 characters";}
|
||||||
}else{$_SESSION["signupError"] = "Password must be at least 4 characters and at most 25 characters";}
|
}else{$_SESSION["signupError"] = "Password must be at least 4 characters and at most 25 characters";}
|
||||||
}else{$_SESSION["signupError"] = "Username must be at least 4 characters and at most 25 characters";}
|
}else{$_SESSION["signupError"] = "Username must be at least 4 characters and at most 25 characters";}
|
||||||
}else{
|
}else{
|
||||||
// If user submitted form wihout actually filling it out completely, send user an error message
|
// If user submitted form wihout actually filling it out completely, send user an error message
|
||||||
if(!empty($_POST)){
|
if(!empty($_POST)){
|
||||||
$_SESSION["signupError"] = "Username and Password are required, please try again";
|
$_SESSION["signupError"] = "All fields are required, please try again";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(PDOException $e){echo "PDOException: ".$e->getMessage();
|
}catch(PDOException $e){echo "PDOException: ".$e->getMessage();
|
||||||
@@ -48,9 +53,11 @@
|
|||||||
<p><?php if($_SESSION['signupError']!=""){ echo $_SESSION['signupError']; } ?></p>
|
<p><?php if($_SESSION['signupError']!=""){ echo $_SESSION['signupError']; } ?></p>
|
||||||
</div>
|
</div>
|
||||||
<h2>And you are...?</h2>
|
<h2>And you are...?</h2>
|
||||||
<h5>Username and password both can be up to 25 alphanumeric characters</h5>
|
<h5>All fields allow up to 25 alphanumeric characters</h5>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
Username: <input type="text" name="signup_username" placeholder="Username"><br />
|
Username: <input type="text" name="signup_username" placeholder="Username"><br />
|
||||||
|
First Name: <input type="text" name="signup_fname" placeholder="Username"><br />
|
||||||
|
Last Name: <input type="text" name="signup_lname" placeholder="Username"><br />
|
||||||
Password: <input type="password" name="signup_password" placeholder="Password"><br />
|
Password: <input type="password" name="signup_password" placeholder="Password"><br />
|
||||||
<br />
|
<br />
|
||||||
<input type="submit" class="button">
|
<input type="submit" class="button">
|
||||||
|
|||||||
Reference in New Issue
Block a user