2021年1月2日星期六

When i try to register an account

Fatal error: Uncaught TypeError: mysqli_real_escape_string(): Argument #1 ($mysql) must be of type mysqli, string given in /home/voeg.me/public_html/server.php:31 Stack trace: #0 /home/voeg.me/public_html/server.php(31): mysqli_real_escape_string() #1 /home/voeg.me/public_html/register.php(1): include('...') #2 {main} thrown in /home/voeg.me/public_html/server.php on line 31

i recieve this error when i try to register an account to my website

$username = "";  $firstname = "";  $lastname = "";  $email    = "";  $errors = array();       if (isset($_POST['reg_user'])) {      $username = mysqli_real_escape_string($db, $_POST['username']);    $firstname = mysqli_real_escape_string($db, $_POST['firstname']);    $lastname = mysqli_real_escape_string($db, $_POST['lastname']);    $email = mysqli_real_escape_string($db, $_POST['email']);    $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);    $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);      if (empty($username)) { array_push($errors, "Gebruikersnaam is verplicht!"); }    if (empty($firstname)) { array_push($errors, "Voornaam is verplicht!"); }      if (empty($lastname)) { array_push($errors, "Achternaam is verplicht!"); }    if (empty($email)) { array_push($errors, "E-mail is verplicht!"); }    if (empty($password_1)) { array_push($errors, "Wachtwoord is verplicht!"); }    if ($password_1 != $password_2) {      array_push($errors, "Uw wachtwoorden komen niet overeen!");    }        $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";    $result = mysqli_query($db, $user_check_query);    $user = mysqli_fetch_assoc($result);        if ($user) {       if ($user['username'] === $username) {        array_push($errors, "Gebruikersnaam is al bezet!");      }        if ($user['email'] === $email) {        array_push($errors, "E-mail is al bezet!");      }    }      if (count($errors) == 0) {      $password = md5($password_1);        $query = "INSERT INTO users (username, firstname, lastname, email, password)                 VALUES('$username', '$firstname', '$lastname', '$email', '$password')";      mysqli_query($db, $query);      $_SESSION['username'] = $username;      $_SESSION['success'] = "Je bent succesvol ingelogd";      header('location: index.php');    }  }```  
https://stackoverflow.com/questions/65545726/when-i-try-to-register-an-account January 03, 2021 at 09:05AM

没有评论:

发表评论