Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Mysql]Jak stworzyć tabelę pod tą rejestrację
kiepski96
post 3.04.2010, 18:14:53
Post #1





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


  1. <?php
  2. $error_message = "";
  3. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  4. {
  5. $action = isset($_POST['action']) ? $_POST['action'] : '';
  6. $mysql_server = 'serwer';
  7. $mysql_username = 'nazwa użytkownika';
  8. $mysql_password = 'hasło';
  9. $mysql_database = 'baza danych';
  10. $mysql_table = 'nazwa tabeli';
  11.  
  12. $success_page = './profil.php';
  13.  
  14. if ($action == 'signup')
  15. {
  16. $newusername = $_POST['username'];
  17. $newemail = $_POST['email'];
  18. $newpassword = $_POST['password'];
  19. $confirmpassword = $_POST['confirmpassword'];
  20. $newfullname = $_POST['fullname'];
  21. if ($newpassword != $confirmpassword)
  22. {
  23. $error_message = 'Hasła nie psują do siebie';
  24. }
  25. else
  26. if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newusername))
  27. {
  28. $error_message = 'Nieprawidłowa nazwa użytkownika';
  29. }
  30. else
  31. if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newpassword))
  32. {
  33. $error_message = 'Wystąpił błąd.Wpisz inne hasło.';
  34. }
  35. else
  36. if (!ereg("^[A-Za-z0-9_!@$.' &]{1,50}$", $newfullname))
  37. {
  38. $error_message = 'Wystąpił błąd przy wprowadzeniu imienia';
  39. }
  40. else
  41. if (!ereg("^.+@.+\..+$", $newemail))
  42. {
  43. $error_message = 'Nieprawidłowy adres email';
  44. }
  45. else
  46. if (isset($_POST['captcha'],$_SESSION['random_txt']) && md5($_POST['captcha']) == $_SESSION['random_txt'])
  47. {
  48. unset($_POST['captcha'],$_SESSION['random_txt']);
  49. }
  50. else
  51. {
  52. $error_message = 'The entered code was wrong.';
  53. }
  54. if (empty($error_message))
  55. {
  56. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  57. mysql_select_db($mysql_database, $db);
  58. $sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
  59. $result = mysql_query($sql, $db);
  60. if ($data = mysql_fetch_array($result))
  61. {
  62. $error_message = 'Nazwa użytkownika jest już zajęta';
  63. }
  64. }
  65. if (empty($error_message))
  66. {
  67. $crypt_pass = md5($newpassword);
  68. $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1)";
  69. $result = mysql_query($sql, $db);
  70. $mailto = $newemail;
  71. $subject = 'Nowe konto';
  72. $message = 'Założono konto stronazasms';
  73. $message .= "\r\nUsername: ";
  74. $message .= $newusername;
  75. $message .= "\r\nPassword: ";
  76. $message .= $newpassword;
  77. $message .= "\r\n";
  78. $header = "From: stronazasms@tlen.pl"."\r\n";
  79. $header .= "Reply-To: stronazasms@tlen.pl"."\r\n";
  80. $header .= "MIME-Version: 1.0"."\r\n";
  81. $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
  82. $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
  83. $header .= "X-Mailer: PHP v".phpversion();
  84. mail($mailto, $subject, $message, $header);
  85. mail('stronazasms@tlen.pl', $subject, $message, $header);
  86. header('Location: '.$success_page);
  87. }
  88. }
  89. }
  90. ?>



Mam taki skrypt rejestracji.
Jaką dodać tabelę do mysql pod ten skrypt?questionmark.gif
Proszę o podanie kodu tabeli.

  1. <?php
  2. if($_SERVER['REQUEST_METHOD'] == 'POST')
  3. {
  4. $success_page = '';
  5. $error_page = basename(__FILE__);
  6. $mysql_server = 'sdbhdncn';
  7. $mysql_username = 'xbxcnn';
  8. $mysql_password = 'shdhd';
  9. $mysql_database = 'asdghsh';
  10. $mysql_table = 'ddcndcn';
  11. $crypt_pass = md5($_POST['password']);
  12. $found = false;
  13. $fullname = '';
  14.  
  15. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  16. mysql_select_db($mysql_database, $db);
  17. $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'";
  18. $result = mysql_query($sql, $db);
  19. if ($data = mysql_fetch_array($result))
  20. {
  21. if ($crypt_pass == $data['password'] && $data['active'] != 0)
  22. {
  23. $found = true;
  24. $fullname = $data['fullname'];
  25. }
  26. }
  27. if($found == false)
  28. {
  29. header('Location: '.$error_page);
  30. }
  31. else
  32. {
  33. $_SESSION['username'] = $_POST['username'];
  34. $_SESSION['fullname'] = $fullname;
  35. $rememberme = isset($_POST['rememberme']) ? true : false;
  36. if ($rememberme)
  37. {
  38. setcookie('username', $_POST['username'], time() + 3600*24*30);
  39. setcookie('password', $_POST['password'], time() + 3600*24*30);
  40. }
  41. header('Location: '.$success_page);
  42. }
  43. }
  44. $username = isset($_COOKIE['username']) ? $_COOKIE['username'] : '';
  45. $password = isset($_COOKIE['password']) ? $_COOKIE['password'] : '';
  46. ?>



Mam taki skrypt logowania.
Jaką dodać tabelę do mysql pod ten skrypt?questionmark.gif
Proszę o podanie kodu tabeli.



Go to the top of the page
+Quote Post
pedro84
post 3.04.2010, 18:27:45
Post #2





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

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


Żartujesz, prawda? Hm...a co to w ogóle jest
Cytat
kod tabeli
?

@down (żeby nie nabijać postow): Czyli jednak da się, hę?

Ten post edytował pedro84 3.04.2010, 18:37:23


--------------------
Google knows the answer...
Go to the top of the page
+Quote Post
kiepski96
post 3.04.2010, 18:40:42
Post #3





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Chodziło mi o taki kod:

CREATE TABLE baza (
id int( 11 ) NOT NULL AUTO_INCREMENT ,
nick varchar( 50 ) NOT NULL default '',
imie varchar( 50 ) NOT NULL default '',
haslo varchar ( 32 ) NOT NULL default '',
email varchar( 100 ) NOT NULL default '',
PRIMARY KEY ( id )
);

Ale podałem tylko przykład,chcę teraz odpowiedni kod do skryptów rejestracji i logowania
Go to the top of the page
+Quote Post
MateuszS
post 3.04.2010, 18:46:57
Post #4





Grupa: Zarejestrowani
Postów: 1 429
Pomógł: 195
Dołączył: 6.10.2008
Skąd: Kraków/Tomaszów Lubelski

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


Sam sobie odpowiedziales na pytanie

  1. CREATE TABLE `users` (
  2. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  3. `username` VARCHAR( 50 ) NOT NULL ,
  4. `password` VARCHAR( 50 ) NOT NULL ,
  5. `fullname` VARCHAR( 50 ) NOT NULL ,
  6. `email` VARCHAR( 100 ) NOT NULL ,
  7. `active` INT NOT NULL
  8. )


gdzie users to nazwa tabeli ;P

Ten post edytował MateuszScirka 3.04.2010, 18:50:19


--------------------
O! Zimniok :P
Go to the top of the page
+Quote Post
kiepski96
post 3.04.2010, 19:35:48
Post #5





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Bardzo ładnie dziękuję.
A czy tak samo będzie dla logowania?

Ten post edytował kiepski96 3.04.2010, 20:02:56
Go to the top of the page
+Quote Post
MateuszS
post 3.04.2010, 20:20:07
Post #6





Grupa: Zarejestrowani
Postów: 1 429
Pomógł: 195
Dołączył: 6.10.2008
Skąd: Kraków/Tomaszów Lubelski

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


Logowanie korzysta z tej samej tabeli,


--------------------
O! Zimniok :P
Go to the top of the page
+Quote Post
kiepski96
post 3.04.2010, 20:36:50
Post #7





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Tylko jest teraz kłopot.
Rejestruję się,wypełniam wszystko,ale po kliknięciu rejestruj odświeża stronę i nic więcej

I czy serwer to localhost questionmark.gif?

Ten post edytował kiepski96 3.04.2010, 20:37:50
Go to the top of the page
+Quote Post
MateuszS
post 3.04.2010, 20:39:14
Post #8





Grupa: Zarejestrowani
Postów: 1 429
Pomógł: 195
Dołączył: 6.10.2008
Skąd: Kraków/Tomaszów Lubelski

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


Ja nie wiem, to twoj skrypt, jezeli skrypt stoi na twoim kompie to za serwer dajesz localhost,


--------------------
O! Zimniok :P
Go to the top of the page
+Quote Post
kiepski96
post 3.04.2010, 20:43:25
Post #9





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Nie,skrypt stoi na xaa.pl

To jaki jest na xaa.pl?
Go to the top of the page
+Quote Post
MateuszS
post 3.04.2010, 20:47:44
Post #10





Grupa: Zarejestrowani
Postów: 1 429
Pomógł: 195
Dołączył: 6.10.2008
Skąd: Kraków/Tomaszów Lubelski

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


Powinni ci podać przy tworzeniu strony, pewnie

localhost / twojastrona.xaa.pl

Ten post edytował MateuszScirka 4.04.2010, 08:24:39


--------------------
O! Zimniok :P
Go to the top of the page
+Quote Post
kiepski96
post 3.04.2010, 22:06:33
Post #11





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'petycja.xaa.pl ' (1) in /home/petycja/public_html/testy/index.php on line 57

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/petycja/public_html/testy/index.php on line 58

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/petycja/public_html/testy/index.php on line 60

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/petycja/public_html/testy/index.php on line 61

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/petycja/public_html/testy/index.php on line 70

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/petycja/public_html/testy/index.php on line 71

Warning: Cannot modify header information - headers already sent by (output started at /home/petycja/public_html/testy/index.php:57) in /home/petycja/public_html/testy/index.php on line 88


Takie błędy się pojawiły przy rejestracji
Jeden dotyczy błędnego hosta,ale co znaczą inne?questionmark.gif
Go to the top of the page
+Quote Post
pedro84
post 3.04.2010, 22:14:47
Post #12





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

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


Chłopie.... na 99% Twoim hostem jest localhost...

Popraw to, a reszta błędów powinna zniknąć (o ile nie masz gdzieś innych).


--------------------
Google knows the answer...
Go to the top of the page
+Quote Post
kiepski96
post 3.04.2010, 22:25:08
Post #13





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 22.02.2010

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


Tak,wszystko już działa,dziękuję i dobranoc
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 10:52