Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\Noten\index.php:16 Stack trace: #0 {main} thrown in C:\


Hxgxn

Grünschnabel
#1
Hi Leute, habe ein Problem aber weiß nicht wie ich es beheben soll...
Fehlermeldung:
Code:
Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\Noten\index.php:16 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Noten\index.php on line 16
Code:
PHP:
<?php
  session_start();

  $conn = new mysqli("localhost","root","","logins");

  $msg="";

  if (isset($_POST['login'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $password = sha1($password);
    $userType = $_POST['userType'];

    $sql = "SELECT * FROM users WHERE username=? AND password=? AND user_type=?";
    $stmt=$conn->prepare($sql);
    $stmt->bind_param("sss",$username,$password,$userType);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();

    session_regenerate_id();
    $_SESSION['username'] = $row['username'];
    $_SESSION['role'] = $row['userType'];
    session_write_close();

    if($result->num_rows==1 && $_SESSION['role']=="student"){
      header("location:student.php");
    }else if ($result->num_rows==1 && $_SESSION['role']=="teacher") {
      header("location:teacher.php");
    }else if ($result->num_rows==1 && $_SESSION['role']=="admin") {
      header("location:admin.php");
    }
    else{
      $msg = "Username or Password is Incorrect!";
    }
  }
 ?>
<!DOCTYPE html>
<html lang="eng" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Login System</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  </head>
  <body class="bg-dark">
    <div class="container">
      <div class="row justify-content-center">
            <div class="col-lg-5 bg-light mt-5 px-0">
              <h3 class="text-center text-light bg-danger p-3">Login System</h3>
              <form class="p-4" action="" method="post">
                <div class="form-group">
                  <input type="text" name="username" class="form-control form-control-lg" placeholder="Nutzername" required>
                </div>
                <div class="form-group">
                  <input type="password" name="password" class="form-control form-control-lg" placeholder="Passwort" required>
                </div>
                <div class="form-group lead">
                  <label for="userType">Ich bin :</label>
                  <input type="radio" name="userType" value="schüler" class="custom-radio" required>&nbsp;Schüler |
                  <input type="radio" name="userType" value="lehrer" class="custom-radio" required>&nbsp;Lehrer |
                  <input type="radio" name="userType" value="admin" class="custom-radio" required>&nbsp;Admin
                </div>
                <div class="form-group">
                  <input type="submit" name="login" class="btn btn-danger btn-block">
                </div>
              </form>
            </div>
      </div>
    </div>
  </body>
</html>
Wäre nice wenn ihr mir helfen könntet.
Danke