PHP:
<?php
session_start();
// Change this to your connection info.
$DATABASE_HOST = '';
$DATABASE_USER = '';
$DATABASE_PASS = '';
$DATABASE_NAME = '';
// Try and connect using the info above.
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
// If there is an error with the connection, stop the script and display the error.
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
// Now we check if the data from the login form was submitted, isset() will check if the data exists.
if ( !isset($_POST['username'], $_POST['email'] , $_POST['password'], $_POST['repassword'], $_POST['code']) ) {
// Could not get the data that should have been sent.
die ('Please fill in all fields!');
}
else if (!filter_var($_POST['email']), FILTER_VALIDATE_EMAIL){
die ('Invalid email!');
}
else if (!preg_match("/^[a-zA-Z0-9]*$/", $_POST['username'])) {
die ('Invalid username!');
}
else if ($_POST['password'] !== $_POST['repassword']) {
die ('Passwords do not match!');
}
else {
$sql = "SELECT username FROM accounts WHERE username = ?";
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die ('SQL Error!');
}
else {
mysqli_stmt_bind_param($stmt, "s", $_POST['username']);
mysqli_stmt_execute($stmt);
mysqli_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows();
if ($resultCheck > 0) {
die ("Username already taken!");
}
mysqli_stmt_bind_param($stmt, "s", $_POST['email']);
mysqli_stmt_execute($stmt);
mysqli_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows();
if ($resultCheck > 0) {
die ("Email already in use!");
}
$sql = "SELECT regcode FROM codes WHERE regcode = ?";
$maxid = 0;
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die ('SQL Error!');
}
else {
mysqli_stmt_bind_param($stmt, "s", $_POST['code']);
mysqli_stmt_execute($stmt);
mysqli_store_result($maxid);
$resultCheck = mysqli_stmt_num_rows();
if ($resultCheck > 0) {
die ("Username already taken!");
}
else {
$sql = "SELECT MAX(id) FROM accounts";
$maxid = 0;
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die ('SQL Error!');
}
else {
mysqli_stmt_execute($stmt);
mysqli_store_result($maxid);
}
$sql = "INSERT INTO accounts (id, username, password, email, customer) VALUES (?, ?, ?, ?, ?)";
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die ('SQL Error!');
}
else {
$hashedpass = password_hash($_POST['password'], PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "isssi", ($maxid + 1), $_POST['email'], $hashedpass, $_POST['email'], 1);
mysqli_stmt_execute($stmt);
}
$sql = "DELETE FROM codes WHERE regcode = ?";
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die ('SQL Error!');
}
else {
mysqli_stmt_bind_param($stmt, "s", $_POST['code']);
mysqli_stmt_execute($stmt);
}
echo "Registration complete!";
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($con);
}
?>
HTML:
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Register</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="wrapper">
<div id="vantajs"></div>
<script src="three.r92.min.js"></script>
<script src="vanta.net.min.js"></script>
<script>
VANTA.NET({
el: "#vantajs",
color: 0xff993f,
backgroundColor: 0x201f22,
points: 13.00,
maxDistance: 17.00,
spacing: 13.00
})
</script>
</div>
<div>
<div class="login">
<h1>A</h1>
<form action="register.php" method="post">
<h4>
Register to gain access to a user panel
</h4>
<input type="text" name="username" placeholder="Username" id="username" required>
<input type="text" name="email" placeholder="Email" id="email" required>
<input type="password" name="password" placeholder="Password" id="password" required>
<input type="password" name="repassword" placeholder="Repeat Password" id="password" required>
<input type="text" name="code" placeholder="Registration Code" id="code" required>
<input type="submit" value="Register">
<a href="https://pleasedont.live/phplogin/index.html">Already have an account? Login here!</a>
</form>
</div>
<div class = "login">
<form>
<a href="https://pleasedont.live/">Back To Landing Page</a>
</form>
</div>
</div>
</body>
</html>
for some reason making a login form like this keeps giving a http 500 error.
any help would be appreciated, thanks alot!