Underneath is the code I typed for my login system. I keep getting an ERROR 500 when I click the submit-signup button. For as far as I know I don't have any syntax errors. I absolutely don't know what I did wrong and would like you guys's advices.
I deleted the $dBUsername and $dBPassword for privacy reasons, sorry :(
The code to connect to the database: back-end/dbh.be.php
<?php
$servername = "localhost":
$dBUsername = "";
$dBPassword = "";
$dBName = "admhap_Users";
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);
if(!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
My signup page, the page you see on the website: signup.php
<?php
require "header.php";
?>
<main>
<div>
<section>
<h1>Aanmelden</h1>
<form action="back-end/signup.be.php" method="post">
<input type="text" name="uid" placeholder="Gebruikersnaam...">
<input type="text" name="mail" placeholder="E-mail...">
<input type="password" name="ww" placeholder="Wachtwoord...">
<input type="password" name="ww-her" placeholder="Herhaal wachtwoord...">
<button type="submit" name="signup-submit">Aanmelden</button>
</form>
</section>
</div>
</main>
<?php
require "footer.php";
?>
The back-end code behind my sigup-page: back-end/signup.be.php
<?php
if (isset($_POST['signup-submit'])) {
require 'dbh.be.php';
$username = $_POST['uid'];
$email = $_POST['mail'];
$password = $_POST['ww'];
$passwordRepeat = $_POST['ww-her'];
if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
exit();
}
else if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invalidmailuid");
exit();
}
else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?error=invalidmail&uid=".$username);
exit();
}
else if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaliduid&mail=".$email);
exit();
}
else if ($password !== $passwordRepeat) {
header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
exit();
}
else {
$sql = "SELECT gebruikersnaam FROM gebruikers WHERE gebruikersnaam=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if ($resultCheck > 0) {
header("Location: ../signup.php?error=usertaken&mail=".$email);
exit();
}
else {
$sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
}
else{
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
mysqli_stmt_execute($stmt);
header("Location: ../signup.php?signup=succes");
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else{
header("Location: ../signup.php?");
exit();
}
?>
Already a massive thank you
Check your code from file: back-end/dbh.be.php in the very first line
$servername = "localhost":
you are using : to terminate line instead of ; that's the main reason you are getting ERROR 500 right after you press submit button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With