Jak można zauważyć na tym filmie, gość łączy się z bazą za pomocą try/catch i potem, za pomocą tej linijki kodu:
$query = $handler->query("SELECT...");
pobiera dane z bazy. Ja ten kod sobie przepisałem i zapisałem w pliku i ten plik dołączyłem do pliku, który rejestruję użytkownika, oto kod:
<?php /* *======================= * REGISTRATION CLASS ! * ====================== */ include_once '/../registration.php'; include_once '/../db_connect/db_connect.php'; class registration { function cryptPass($password1, $rounds = 9){ /* funkcja kryptująca hasło */ } function registration_method($username, $password1, $password2, $email, $date) { if(!empty($username) && !empty($password1) && !empty($password2)) { if(strlen($username) > 20 || strlen($username) < 3 || strlen($password1) > 20 || strlen($password1) < 6 || $password1 != $password2) { echo 'Registration unsuccessfully. Entered data are incorrect. ◄ Back'; } else { $q = $connect->query("SELECT username, email FROM users WHERE username = '$username' OR email = '$email'"); if($q->rowCount() != 1){ echo 'Registration successfully. Entered data are correct.'; $password = $this->cryptPass($password1); // hashed password $q = $connect->query("INSERT INTO users(username, password, email, date) VALUES ('$username', '$password', '$email', '$date')"); $activating_link = 'http://localhost/web-cms/activating.php?acc='.$username.'&email='.$email.''; echo $activating_link; /* SENDING AN EMAIL FOR ACTIVATE AN ACCOUNT */ $text = '
Now, check out your e-mail box and activate your account on our site. See you later !Hello '.$username.'
You are welcome in Szkoła WEB. You\'ve created arleady an account, but you can\'t still be logged in ! For activate your account, click here.
Greets you Szkoła WEB
'; $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=utf-8' . "\r\n"; /* END OF THE MAIL */ mail($email, 'Activating an account by SzkołaWEB', $text, $header); } else { echo 'Registration unsuccessfully. User arleady exist. ◄ Back'; } } } } } ?>
I teraz mam taki błąd:
Notice : Undefined variable: connect in C:\xampp\htdocs\web-cms\classes\registration.php on line 33
Fatal error : Call to a member function query() on a non-object in C:\xampp\htdocs\web-cms\classes\registration.php on line 33
Jak mogę mieć błędy, kiedy kod po prostu przepisałem ? Jakby ktoś pomógł, to byłbym wdzięczny
Pozdrawiam
PS.: Linia nr 33
$q = $connect->query(“SELECT username, email FROM users WHERE username = ‘$username’ OR email = ‘$email’”);