Fatal error: Uncaught Error: Call to a member function bind_param() [duplicate]

  html, mysql, mysqli, php, phpmyadmin

I’m making a simple register website and i have some problems with sending it to my database.
I tried allot of things but i could figure out why its happening

This error accurs:

Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:xampphtdocsmySiteinsert.php:48 Stack trace: #0 {main} thrown in C:xampphtdocsmySiteinsert.php on line 48

This is my registration site:

<!DOCTYPE html>
<html>
    <head>
        <title>Register</title>
        <meta charset="utf-8">
        <!<link rel="stylesheet" href="css/style.css">
    </head>
    <body>
        <header>
            <a href="login.html">Login</a>
            <h1>Register:</h1>
        </header>
        <main>
            <section id="kontakt">
                <br> <br>
                <form action="insert.php" method="post">
                    <p>Username:</p>
                    <input type="text" name="username" placeholder="Username" required> <br> 
                    <p>Name:</p>
                    <input type="text" name="firstname" placeholder="Firstname" required>
                    <!--<p>Lastname:</p>-->
                    <input type="text" name="lastname" placeholder="Lastname" required> <br> 
                    <p>Gender:</p>
                    <input type="radio" name="gender" value="m" required>Male
                    <input type="radio" name="gender" value="f" required>Female
                    <input type="radio" name="gender" value="o" required>Others <br> 
                    <p>Email:</p>
                    <input type="email" name="email" placeholder="Email" required> <br>
                    <p>Password:</p>
                    <input type="password" name="password" placeholder="Password" required>
                    <br> 
                    <input type="submit" name="submit">
                </form>
            </section>
        </main>
    </body>
</html>

this is my php code where the error is:

<?php
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$email = $_POST['email'];
    
if (!empty($username) || !empty($firstname) || !empty($lastname) || !empty($password) || !empty($gender) || !empty($email)) {
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);
    
    $host = "localhost";
    $dbUsername = "root";
    $dbPassword = "123456";
    $dbname = "register";
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
    
    if (mysqli_connect_error()) {
        die('Connect Error('. mysqli_connect_errno() .')'. mysqli_connect_error()); 
        
    } else {
        $SELECT = "SELECT email From register Where email = ? Limit 1";
        $INSERT = "INSERT Into register (username, firstname, lastname, password, gender, email) values($username, $firstname, $lastname, $hashed_password, $gender, $email)";
        
        $stmt = $conn->prepare($SELECT);
        $stmt->bind_param("s", $email);
        $stmt->execute();
        $stmt->bind_result($email);
        $stmt->store_result();
        $rnum = $stmt->num_rows;
        
        if ($rnum==0) {
            $stmt->close();
            $stmt = $conn->prepare($INSERT);
            $stmt->bind_param("ssssss", $username, $firstname, $lastname, $password, $gender, $email);
            $stmt->execute();
            echo "New record inserted sucessfully!";
        } else {
            echo "Someone already register using this email";
        }
        $stmt->close();
        $conn->close();
    }
} else {
    echo "All field are required";
    die();
}
?>

would be nice if someone can help me out with it ^^

Source: Ask PHP

LEAVE A COMMENT