Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]rejestracja, Tworzenie nowej tabeli podczas rejestracji
jaca121212
post
Post #1





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

Ostrzeżenie: (0%)
-----


Witam,
Jak zrobić żeby user który zarejestruje się utworzyła się w bazie danych nowa tabela z jego loginem wpisanym przy rejestracji
podam kod rejestracji nie wiem za bardzo gdzie wstawić kod z tworzeniem tabeli w bazie ktoś z was mógłby mnie nakierować jak to zrobić.
  1. <?php
  2.  
  3.  
  4. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email']))) {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "connect.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno != 0) {
  12. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  13. die();
  14. }
  15.  
  16. $login = trim($_POST['login']);
  17. $email = trim($_POST['email']);
  18. $haslo = trim($_POST['haslo']);
  19. $haslo1 = trim($_POST['haslo1']);
  20. $data = date('Y-m-d H:i:s');
  21. $ip = $_SERVER['REMOTE_ADDR'];
  22. $errors = array();
  23.  
  24. if (empty($login)) {
  25. $errors[] = 'Login jest pusty';
  26. $_SESSION['blad5'] = '<p class="komunikat">Login jest pusty.Nie podałeś loginu!</p>';
  27. header('Location: index.php');
  28. }
  29.  
  30. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE user= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $login)));
  31. if ($resultat->num_rows == 1) {
  32. $errors[] = "Taki login już istnieje ";
  33. $_SESSION['blad6'] = '<p class="komunikat">Taki login już istnieje!</p>';
  34. header('Location: index.php');
  35.  
  36. }
  37.  
  38. if (empty($haslo) || empty($haslo1)) {
  39. $errors[] = 'Wpisz hasła';
  40. $_SESSION['blad7'] = '<p class="komunikat">Wpisz hasła!</p>';
  41. header('Location: index.php');
  42. }
  43.  
  44. if ($haslo != $haslo1) {
  45. $errors[] = "Wpisane hasła różnią się.";
  46. $_SESSION['blad8'] = '<p class="komunikat">Wpisane hasła różnią się!</p>';
  47. header('Location: index.php');
  48. }
  49.  
  50. if (empty($_POST['email'])) {
  51. $errors[] = "Adres E-mail jest pusty.";
  52. $_SESSION['blad9'] = '<p class="komunikat">Adres E-mail jest pusty.</p>';
  53. header('Location: index.php');
  54. }
  55. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE email= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $email)));
  56. if ($resultat->num_rows == 1) {
  57. $errors[] = "Taki adres e-mail już istnieje ";
  58. $_SESSION['blad10'] = '<p class="komunikat">Taki adres e-mail już istnieje!</p>';
  59. header('Location: index.php');
  60. }
  61. if (count($errors) == 0) {
  62. // Brak błędów, to rejestrujemy
  63.  
  64. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  65. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  66. // Hasjujemy hasło
  67. $hash = hash('sha512', $haslo . $sol . $sol2);
  68.  
  69. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  70. $email = htmlentities($email, ENT_QUOTES, "UTF-8");
  71.  
  72. $resultat = $polaczenie->query(sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`, `data`, `ip`) VALUES ('', '%s', '%s', '%s', '%s','%s')",
  73. mysqli_real_escape_string($polaczenie, $login),
  74. mysqli_real_escape_string($polaczenie, $hash),
  75. mysqli_real_escape_string($polaczenie, $email),
  76. mysqli_real_escape_string($polaczenie, $data),
  77. mysqli_real_escape_string($polaczenie, $ip)));
  78. $_SESSION['komunikat'] = '<p class="komunikat">Zostałeś/aś poprawnie zarejestrowany/na. Zaloguj się!</p>';
  79. $_SESSION['zarejestrowany'] = true;
  80. header('Location: index.php');
  81. } else {
  82. // Są błędy
  83. echo '<p class="komunikat">' . implode('<br>', $errors) . '</p>';
  84. }
  85.  
  86. $polaczenie->close();

a zapomniałem dodać kod do tabeli
  1. CREATE TABLE (nik usera podany przy rejestracji) (
  2. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  3. firstname VARCHAR(30) NOT NULL,
  4. lastname VARCHAR(30) NOT NULL,
  5. email VARCHAR(50),
  6. reg_date TIMESTAMP
  7. )

z góry dziękuje za pomoc

Ten post edytował jaca121212 14.08.2015, 06:06:57
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 05:40