I am currently working on a simple registration form for an application that I'm building. I have nearly completed my build but am currently struggling with a registration form which is crucial to my project. I keep getting a HTTP 500 error saying "This page is not working" when I click the submit button on my form... I have tried a lot of different things to fix it but no luck... Any help is appreciated!
Here is the code:
session_start();
require 'connect.php';
if(isset($_POST['register'])){
$firstname = !empty($_POST['username']) ? trim($_POST['firstname']) : null;
$lastname = !empty($_POST['password']) ? trim($_POST['lastname']) : null;
$username = !empty($_POST['username']) ? trim($_POST['username']) : null;
$pass = !empty($_POST['password']) ? trim($_POST['password']) : null;
//TO ADD: Error checking (username characters, password length, etc).
$sql = "SELECT COUNT(username) AS num FROM credentials WHERE username = :username";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':username', $username);
//Execute.
$stmt->execute();
//Fetch the row.
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row['num'] > 0){
die('That username already exists!');
}
$sql = "INSERT INTO credentials (username, password) VALUES (:username, :password)";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':username', $username);
$stmt->bindValue(':password', $password);
$result = $stmt->execute();
if($result){
echo 'Thank you for registering.';
}
}
And I was also curious as to how you could log the user in right after they successfully submit their registration form and display their username on the welcome page... I am fairly new to PHP so I am very curious about some things! Thanks again guys!