0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Hey and welcome to SO. You need to enable error reporting in your PHP environment. By default production errors are hidden to avoid security risks. https://stackify.com/display-php-errors/ Put this at the top of your file inside PHP tags `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);` – AsTeR Jun 24 '22 at 12:51
  • 1
    Since you've commented out the `createUser` function, then if you submit the form without any validation problems, then quite simply your code will do nothing useful...nothing is output, no redirect is made, nothing visible will happen. If you're not ready to enable that function yet, just add a simple `echo "here";` or something instead of it, so you can check if the code definitely reached that point in the process. – ADyson Jun 24 '22 at 12:53
  • Thanks for the suggestions. I have been able to fix my issue using both your comments and users now sign up. I have got another problem that has been exposed by fixing the first that I can't solve but its a separate issue so I will open a new question. – MTacoFTW Jun 26 '22 at 16:55

0 Answers0