Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php/sql] problem z logowaniem i rejestracja
Forum PHP.pl > Forum > Przedszkole
mariuszzzzzz
Witam wszystkich.

W php nie jestem dobry, dlatego tez sciagnalem sobie gotowca na logowanie i rejestrowanie uzytkownikow.

Niestety nie dziala prawidlowo. Gdy sie rejestruje nowa osobe to skrypt nie wpisuje tych danych do bazy danych a co za tym idzie nie da sie zalogowac.

login.php
  1. <?php
  2. require("./CustomSql.inc.php");
  3. $db = new CustomSQL($DBName);
  4. $showtable = true;
  5. $errortag = false;
  6. if (!empty($userlogin)) {
  7.  
  8. if (empty($username)){
  9. $errortag = true;
  10. $errormsg = $error_usernameempty;
  11. }
  12.  
  13. if (empty($password)){
  14. $errortag = true;
  15. $errormsg = $error_passwordempty;
  16. }
  17.  
  18. $customerid = $db->logincheck($username,$password);
  19. if ($customerid==0) {
  20. $errortag = true;
  21. $errormsg = $error_wrongpassword;
  22. }
  23.  
  24. if (!$errortag){
  25. $CID = $customerid;
  26. $showtable = false;
  27. }
  28.  
  29. }
  30.  
  31. if (session_is_registered("CID")){
  32. $showtable = false;
  33. }
  34.  
  35. ?>
  36. <html>
  37. <head>
  38. <title><?php print "$front_login"; ?></title>
  39. <meta http-equiv="Content-Type" content="text/html; charset=<?php print "$front_charset"; ?>">
  40. <link rel="stylesheet" href="./style/style.css" type="text/css">
  41. <script language="JavaScript">
  42. <!--
  43. function MM_reloadPage(init) { //reloads the window if Nav4 resized
  44. if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
  45. document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
     }}
  46. else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
  47. }
  48. MM_reloadPage(true);
  49. // -->
  50. </script>
  51. </head>
  52.  
  53. <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
  54. <?php
  55. include("top.php3");
  56. ?>
  57. <table width="770" border="0" cellspacing="1" cellpadding="0" align="center" class="table_01">
  58. <tr> 
  59. <td class="table_02" width="160" valign="top"> 
  60. <table width="160" border="0" cellspacing="0" cellpadding="4">
  61. <tr> 
  62. <td> </td>
  63. </tr>
  64. <tr> 
  65. <td> </td>
  66. </tr>
  67. </table>
  68. </td>
  69. <td class="menu" bgcolor="#FFFFFF" valign="top" width="610"> 
  70.  <table border="0" cellspacing="0" cellpadding="4" width="610">
  71. <tr> 
  72. <td bgcolor="#F2F2F2" class="menu_in">::<?php print "$front_login"; ?>   <font color="#FF0000">*</font> <?php print "$front_requiredinfo"; ?></td>
  73. </tr>
  74. <?php
  75. if ($errortag){
  76. ?>
  77. <tr> 
  78. <td><font color="#FF0000"><?php print "$errormsg"; ?></font></td>
  79. </tr>
  80. <?php
  81. }
  82. ?>
  83. <tr> 
  84. <td>
  85. <?php
  86. if ($showtable){
  87. ?>
  88. <form action="<?php print "$PHP_SELF"; ?>" method="POST">
  89. <table border=0 cellpadding=2 cellspacing=2>
  90. <tr><td width="120"><?php print "$front_username"; ?> : </td><td><input type="text" name="username" value="<?php print "$username"; ?>"> <font color="#FF0000">*</font></td></tr>
  91. <tr><td><?php print "$front_password"; ?> : </td><td><input type="password" name="password" value=""> <font color="#FF0000">*</font></td></tr>
  92. <tr><td><a href="register.php"><?php print "$front_registration"; ?></a>   <a href="forgetpass.php"><?php print "$front_forgetpass"; ?></a></td><td><input type="submit" name="userlogin" value="<?php print "$front_login"; ?>"></td></tr>
  93. </table>
  94. </form>
  95. <?php
  96. }
  97. else{
  98. ?>
  99. <a href="modiinfo.php"><?php print "$front_zobacz"; ?></a>   <a href="modiinfo.php"><?php print "$front_modiinfo"; ?></a>   <a href="modipass.php"><?php print "$front_modipass"; ?></a>
  100. <?php
  101. }
  102. ?>
  103. </td>
  104. </tr>
  105. <tr> 
  106. <td align="right"> </td>
  107. </tr>
  108. </table>
  109. </td>
  110. </tr>
  111. </table>
  112. <?php
  113. include("bottom.php3");
  114. ?>
  115. </body>
  116. </html>



register.php
  1. <?php
  2. require("./CustomSql.inc.php");
  3. $db = new CustomSQL($DBName);
  4. $showtable = true;
  5. $errortag = false;
  6. if (!empty($adduser)) {
  7.  
  8. if (empty($username)){
  9. $errortag = true;
  10. $errormsg = $error_usernameempty;
  11. }
  12.  
  13. if (empty($password)){
  14. $errortag = true;
  15. $errormsg = $error_passwordempty;
  16. }
  17.  
  18. if (empty($email)){
  19. $errortag = true;
  20. $errormsg = $error_emailempty;
  21. }
  22.  
  23. $usernamecheckresult = $db->checkusername($username);
  24. if (!empty($usernamecheckresult)) {
  25. $errortag = true;
  26. $errormsg = $error_userexist;
  27. }
  28.  
  29. if ($password!=$passretype){
  30. $errortag = true;
  31. $errormsg = $error_passretypewrong;
  32. }
  33.  
  34. if ($email!=$emailretype){
  35. $errortag = true;
  36. $errormsg = $error_emailretypewrong;
  37. }
  38.  
  39. if (!ereg("@", $email)) {
  40. $errortag = true;
  41. $errormsg = $error_email;
  42. }
  43.  
  44. if (!$errortag){
  45. $customerid = $db->adduser($username,$password,$email,$homepage,$icq,$aol,$yahoo,$msn,$location,$occupation,$interests,$biography);
  46. $showtable = false;
  47. }
  48.  
  49. }
  50.  
  51. ?>
  52. <html>
  53. <head>
  54. <title><?php print "$front_registration"; ?></title>
  55. <meta http-equiv="Content-Type" content="text/html; charset=<?php print "$front_charset"; ?>">
  56. <?php
  57. if (!empty($customerid)){
  58. ?>
  59. <meta http-equiv="refresh" content="0;URL=login.php">
  60. <?php
  61. }
  62. ?>
  63. <link rel="stylesheet" href="./style/style.css" type="text/css">
  64. <script language="JavaScript">
  65. <!--
  66. function MM_reloadPage(init) { //reloads the window if Nav4 resized
  67. if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
  68. document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
     }}
  69. else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
  70. }
  71. MM_reloadPage(true);
  72. // -->
  73. </script>
  74. </head>
  75.  
  76. <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
  77. <?php
  78. include("top.php3");
  79. ?>
  80. <table width="770" border="0" cellspacing="1" cellpadding="0" align="center" class="table_01">
  81. <tr> 
  82. <td class="table_02" width="160" valign="top"> 
  83. <table width="160" border="0" cellspacing="0" cellpadding="4">
  84. <tr> 
  85. <td> </td>
  86. </tr>
  87. <tr> 
  88. <td> </td>
  89. </tr>
  90. </table>
  91. </td>
  92. <td class="menu" bgcolor="#FFFFFF" valign="top" width="610"> 
  93.  <table border="0" cellspacing="0" cellpadding="4" width="610">
  94. <tr> 
  95. <td bgcolor="#F2F2F2" class="menu_in">::<?php print "$front_registration"; ?>   <font color="#FF0000">*</font> <?php print "$front_requiredinfo"; ?></td>
  96. </tr>
  97. <?php
  98. if ($errortag){
  99. ?>
  100. <tr> 
  101. <td><font color="#FF0000"><?php print "$errormsg"; ?></font></td>
  102. </tr>
  103. <?php
  104. }
  105. ?>
  106. <tr> 
  107. <td>  
  108. <?php
  109. if ($showtable){
  110. ?>  
  111. <form action="<?php print "$PHP_SELF"; ?>" method="POST">
  112. <table border=0 cellpadding=2 cellspacing=2>
  113. <tr><td width="120"><?php print "$front_username"; ?> : </td><td><input type="text" name="username" value="<?php print "$username"; ?>"> <font color="#FF0000">*</font></td></tr>
  114. <tr><td><?php print "$front_password"; ?> : </td><td><input type="password" name="password" value=""> <font color="#FF0000">*</font></td></tr>
  115. <tr><td><?php print "$front_passwordagain"; ?> : </td><td><input type="password" name="passretype" value=""> <font color="#FF0000">*</font></td></tr>
  116. <tr><td><?php print "$front_email"; ?> : </td><td><input type="text" name="email" value="<?php print "$email"; ?>"> <font color="#FF0000">*</font></td></tr>
  117. <tr><td><?php print "$front_emailagain"; ?> : </td><td><input type="text" name="emailretype" value=""> <font color="#FF0000">*</font></td></tr>
  118. <tr><td><?php print "$front_homepage"; ?> : </td><td><input type="text" name="homepage" value="<?php print "$homepage"; ?>"></td></tr>
  119. <tr><td><?php print "$front_icq"; ?> : </td><td><input type="text" name="icq" value="<?php print "$icq"; ?>"></td></tr>
  120. <tr><td><?php print "$front_aol"; ?> : </td><td><input type="text" name="aol" value="<?php print "$aol"; ?>"></td></tr>
  121. <tr><td><?php print "$front_yahoo"; ?> : </td><td><input type="text" name="yahoo" value="<?php print "$yahoo"; ?>"></td></tr>
  122. <tr><td><?php print "$front_location"; ?> : </td><td><input type="text" name="location" value="<?php print "$location"; ?>"></td></tr>
  123. <tr><td><?php print "$front_occupation"; ?> : </td><td><input type="text" name="occupation" value="<?php print "$occupation"; ?>"></td></tr>
  124. <tr><td><?php print "$front_interests"; ?> : </td><td><input type="text" name="interests" value="<?php print "$interests"; ?>"></td></tr>
  125. <tr><td><?php print "$front_biography"; ?> : </td><td><input type="text" name="biography" value="<?php print "$biography"; ?>"></td></tr>
  126. <tr><td></td><td><input type="submit" name="adduser" value="<?php print "$front_regsubmit"; ?>"></td></tr>
  127. </table>
  128. </form>
  129. <?php
  130. }
  131. ?>
  132. </td>
  133. </tr>
  134. <tr> 
  135. <td align="right">  </td>
  136. </tr>
  137. </table>
  138. </td>
  139. </tr>
  140. </table>
  141. <?php
  142. include("bottom.php3");
  143. ?>
  144. </body>
  145. </html>



hmmm czy tu jest cos pokrecone?! dry.gif
Darti
Taki zapis wymaga w³±czonego register_globals. Je¶li jest wy³±czony to musisz te zmienne przechwyciæ z tablicy $_POST.
Oczywi¶cie to tylko jedna z mo¿liwych sugestii...

  1. <?php
  2. if (!$errortag){
  3. $customerid = $db->adduser($username,$password,$email,$homepage,$icq,$aol,$yahoo,$msn,$location,$occupation,$interests,$biography);
  4. $showtable = false;
  5. }
  6. ?>
Darti
bo nie tylko w podanym miejscu masz zmieniæ ale wszêdzie, gdzie odwo³ujesz siê do zmiennych z formularza.
mariuszzzzzz
zrobilem troche zmian w kodzie logowania. Teraz loguje sie normalnie udalo sie smile.gif

ale co mi brakuje - to zeby po zalogowaniu pokazal sie profil/dane ktore naleza do tego loginu podanego przy logowaniu.
jak by to zrobic czym sie posluzyc?
noels
wykorzystaæ:

- php
- sql
- html

Po zalogowaniu wywolac zapytanie do bazy ktore pobierze informacje w niej zapisane dotyczace danego uzytkownika, a nastepnie wyswietli je na ekran.
mariuszzzzzz
tak, ale jak to zrobic. Morzecie mi podac tylko kod ktory bedzie wywolywal dane z bazy z tego login-u?

to potrzebuje dalej powinienem sobie poradzic.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.