I am a noob at web dev but have been trying to improve my skills over the last few months. I have made this sign up script for my website that runs when a user has filled in their details and clicks sign up. The purpose is to pass their details into my SQL database. It isn't working though and just shows a blank white page with no error messages.
The code below is my file called signup.inc.php
<?php
if (isset($_POST["submit"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$username = $_POST["uid"];
$pwd = $_POST["pwd"];
$pwdRepeat = $_POST["pwdrepeat"];
// require_once 'dbh.inc.php';
require_once 'functions.inc.php';
if(emptyInputSignup($name, $email, $username, $pwd, $pwdRepeat) !== false) {
header("location: ../signup.php?error=emptyinput");
exit();
}
if(invalidUid($username) !== false) {
header("location: ../signup.php?error=invaliduid");
exit();
}
if(invalidEmail($email) !== false) {
header("location: ../signup.php?error=invalidemail");
exit();
}
if(pwdMatch($pwd, $pwdRepeat) !== false) {
header("location: ../signup.php?error=passwordsdontmatch");
exit();
}
if(uidExists($conn, $username, $email) !== false) {
header("location: ../signup.php?error=usernametaken");
exit();
}
// createUser($conn, $name, $email, $username, $pwd);
}
else {
header("location: ../signup.php");
exit();
}
It calls dbh.inc.php which I use whenever I want to connect to my main database. dbh.inc.php is below.
$servername = "localhost";
$username = "asad";
$password = "";
$dbname = "tpsc";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I want this to work whereby a user can fill in their details on the sign up page and the variables are then passed to these scripts to be put into my database. I have attached the relevant section of the sign up page below for reference:
<section class="signup-form">
<h2>Sign Up</h2>
<form action="includes/signup.inc.php" method="post">
<input type="text" name="name" placeholder="Full Name">
<input type="text" name="email" placeholder="Email Address">
<input type="text" name="uid" placeholder="Username">
<input type="password" name="pwd" placeholder="Password">
<input type="password" name="pwdrepeat" placeholder="Confirm Password">
<button type="submit" name="submit">Sign Up!</button>
</form>
<?php
if (isset($_GET["error"])) {
if ($_GET["error"] == "emptyinput") {
echo "<p class='psyel'>Fill in all fields!</p>";
}
else if ($_GET["error"] == "invaliduid") {
echo "<p class='psyel'>Choose a propper username!</p>";
}
else if ($_GET["error"] == "invalidemail") {
echo "<p class='psyel'>Choose a propper email!</p>";
}
else if ($_GET["error"] == "passwordsdontmatch") {
echo "<p class='psyel'>Passwords do not match!</p>";
}
}
?>
Apologies in advance if their are obvious mistakes or if the solution is quite simple. I am still in the learning stages.