HTML Button brings me to blank page

So i tried to code a Registration system using HTML and php. But when i press the regist button, the page reloads(still same file) and i just get a blank page. I also have all the time a empty red field(There should stand the errors in if somebody submits unvalid information).
I did a little trubleshooting and when i set a echo in line 14 from the authKontroller and set the rest to comment im getting that echo, so the problem is in the authKontroller.
But i cant find the mistake. I tribblechecked all linked stuff and they are linked correctly so i just gonna post the two important codes.

…/Kontroller/authKontroller.php(The file that creates the Mistake)

<?php

session_start();

require "../config/db.php" ;

$errors = array();
$name = "";
$email = "";


//klickt jemand auf registrieren
if(isset($_POST["registrierungs-knopf"])) {
    
    $name = $_POST["name"];
    $email = $_POST["email"];
    $passwort = $_POST["passwort"];
    $passwortbestätigung = $_POST["passwortbestätigung"];

    if (empty($name)) {
        $errors["name"] = "Ein Name ist erforderlich";
    }

    if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errors["email"] = "Die E-Mail Adresse muss gültig sein";


    }

    if (empty($email)) {
        $errors["email"] = "Eine E-Mail ist erforderlich";

    }

    if (empty($passwort)) {
        $errors["passwort"] = "Ein Passwort ist erforderlich";

    }

    if($passwort != $passwortbestätigung ) {
        $errors["passwort"] = "Die Passwörter müssen übereinstimmen";
    }

    $emailQuery = "SELECT * FROM users WHERE email=? LIMIT 1 ";
    $stmt = $conn->prepare($emailQuery);
    $stmt ->bind_param("s", $email);
    $stmt ->execute();
    $result = $stmt->get_result();
    $userCount = $result->num_rows;
    $stmt ->close();

    if($userCount > 0) {
        $errors["email"] = "Email already exists";
    }

    if (count($errors) === 0) {
        $passwort = password_hash($passwort, PASSWORD_DEFAULT);
        $zeichen = bin2hex(random_bytes(50));
        $bestätigt = false;

        $sql = "INSERT INTO users (name, email, bestätigt, zeichen, passwort) VALUES (?, ?, ?, ?, ?,)";
        $stmt = $conn->prepare($sql);
        $stmt ->bind_param("ssbss", $name, $email, $bestätigt, $zeichen, $passwort );

        if ($stmt ->execute()) {
            $user_id = $conn->insert_id;
            $_SESSION["id"] = $user_id;
            $_SESSION["name"] = $name;
            $_SESSION["email"] = $email;
            $_SESSION["bestätigt"] = $bestätigt;
            //flash message
            $_SESSION["message"] = "Du bist eigeloggt";
            $_SESSION["alert-class"] = "alert-success";
            header("location: ../Registrierung/taxinico.php ");
            exit();




        } else{
            $errors["db_error"] = "Database Fehler: Registrierung fehlgeschlagen";
        }


    } 

    

}

?>

and the registration field …/Registrierung/registriereung.php

<?php require_once "../Kontroller/authKontroller.php" ?>
<!Doctype html>
<html lang="de">
    <head><?
        <meta charset="UTF-8">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="style.css">
        <title>Registrierung</title>
      
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-4 offset-md-4 form-div">
                    <form action="registrierung.php" method="post">
                        <h3 class="text-center">Registrieren</h3>

                        <?php if(count($errors > 0)): ?>
                            <div class="alert alert-danger">
                                <?php foreach($errors as $error): ?>
                                    <li><?php echo $error; ?></li>

                                <?php endforeach; ?>
                            </div>

                        <?php endif; ?> 

                        <div class="form-group">
                            <label for="name">Name</label>
                            <input type="text" name="name" value="<?php echo $name; ?>" class="form-control form-control-lg Box">
                        </div>

                        <div class="form-group">
                            <label for="email">E-mail</label>
                            <input type="email" name="email" value="<?php echo $email; ?>" class="form-control form-control-lg Box">
                        </div>

                        <div class="form-group">
                            <label for="passwort">Passwort</label>
                            <input type="text" name="passwort" class="form-control form-control-lg Box">
                        </div>

                        <div class="form-group">
                            <label for="passwortbestätigung">Passwort wiederholen</label>
                            <input type="text" name="passwortbestätigung" class="form-control form-control-lg Box">
                        </div>

                        <div class="form-group button">
                            <button type="submit" name="registrierungs-knopf" class="w-100 btn btn-lg btn-primary">Registrieren</button>

                        </div>

                        <p class="text-center">Schon Registriert? Einfach <a href="einloggen.php">hier</a> Einloggen</p>

                    </form>

                </div>
            </div>
        </div>
   

    </body>



</html>

Thanks a lot for helping
Paul

Wow… it’s so impenetrable. I mean: it’s not ok that HTML/PHP varies from line to line. There should be one HTML frame filled with PHP created HTML tags, not HTML-PHP-HTML-PHP.
Anyway: I think the blank page what you see, will be an error page. Try to print the php or mysql errors using this: https://stackify.com/display-php-errors/

well if i incloud
ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1);
error_reporting(E_ALL);

in my authKontroller, it display a error that on registrierung.php in line 19 (the php thing) $errors must be a array even though it is, but i can fix that later. I just deleted that block since its not mendetory to the code. It still lodes the same empty page.

Sorry, im pretty new to php and tried to not write it in one document as much as i could but i dintn see an other way then to include the 2 lines of php in the html script

ohh i messed it a bit up

Fatal error : Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\Webseite\Kontroller\authKontroller.php:46 Stack trace: #0 C:\xampp\htdocs\Webseite\Registrierung\registrierung.php(1): require_once() #1 {main} thrown in C:\xampp\htdocs\Webseite\Kontroller\authKontroller.php on line 46

here is the error

solved it. I was pretty dumb and missspelled the databse tabel name

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.