Exception or error:
Trying to set up a panel for my users to view login-only content and I’m currently having an issue where people can register using the same username/email anybody know how to fix this I’ve tried a few different lines of code any advice?
Here’s my current signup.php
<?php
require_once 'source/db_connect.php';
if(isset($_POST['signup-btn'])) {
$username = $_POST['user-name'];
if($username == '' || empty($username)){
echo "<body style='background-color:#212121'><br><br><br><br><br><br><br><br><br><br><br><br><center><font size='12' color='red'>Username cannot be blank..</font></center> <br><br><br> <center><a href='register.html'><font size='5'>Click To Return.</font></a></body>";
return false;
}
$email = $_POST['user-email'];
if(strpos($email, '@') == false || strpos($email, '.') == false){
echo "<body style='background-color:#212121'><br><br><br><br><br><br><br><br><br><br><br><br><center><font size='12' color='red'>Invalid Email Adress..</font></center> <br><br><br> <center><a href='register.html'><font size='5'>Click To Return.</font></a></body>";
return false;
}
$password = $_POST['user-pass'];
if($password == '' || empty($password)){
echo "<body style='background-color:#212121'><br><br><br><br><br><br><br><br><br><br><br><br><center><font size='12' color='red'>Password cannot be blank..</font></center> <br><br><br> <center><a href='register.html'><font size='5'>Click To Return.</font></a></body>";
return false;
}
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
try {
$SQLInsert = "INSERT INTO users (username, password, email, to_date)
VALUES (:username, :password, :email, now())";
$statement = $conn->prepare($SQLInsert);
$statement->execute(array(':username' => $username, ':password' => $hashed_password, ':email' => $email));
if($statement->rowCount() == 1) {
header('location: success.html');
}
}
catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
How to solve: