Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/mysql] problem z skryptem logowania
Majcok12
post
Post #1





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Mam problem z systemem newsow, tzn. zrobilem link "wiecej" w ktorym bedzie zawarta dalsza czesc newsa i tu jest problem, gdyz gdy klikam wiecej w obojetnie jakim newsie zawsze w stronie, ktora sie otworzy jest dalsza czesc newsa, ale ostatniego, ktory jest pobierany z bazy danych i nie wiem jak sobie z tym poradzic.
ponizej kod skryptu:
  1. <?php
  2. include &#092;"common.php\";
  3.  
  4. global $id_polaczenia;
  5. $id_polaczenia = db_connect();
  6. if(!$id_polaczenia) error_message(sql_error());
  7.  
  8. html_header();
  9. echo &#092;"<TR>n\";
  10. echo &#092;"<TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>News</b></center></TD>n\";
  11. echo &#092;"</TR>n\";
  12. echo &#092;"</table>n\";
  13. echo &#092;"<TABLE BORDER=\"0\" cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1200\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">n\";
  14. echo &#092;" <TR>n\";
  15. echo &#092;"  <TD valign=\"top\" align=\"left\" bgcolor=\"#414141\" colspan=\"3\">n\";
  16. echo &#092;"<br>n\";
  17.  
  18. $query = &#092;"SELECT news_headline, add_ndate, autor, news_contents, more, news_id, edit_
    n
  19. m FROM news ORDER BY news_num DESC LIMIT 0, 6\";
  20. $wynik = mysql_query($query);
  21. if(!$wynik) error_message(sql_error());
  22.  
  23. while ($q_data = mysql_fetch_array($wynik)) {
  24.     $naglowek = $q_data[\"news_headline\"];
  25.     $data = $q_data[\"add_ndate\"];
  26.     $autor = $q_data[\"autor\"];
  27.     $zawartosc_p = $q_data[\"news_contents\"];
  28.     $zawartosc_k = $q_data[\"more\"];
  29.     $id_news = $q_data[\"news_id\"];
  30.     $edit_n = $q_data[\"edit_num\"];
  31.  
  32. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9pt; color: gray;\"><b> $naglowek </b><br>n\";
  33. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9px; color: darkgray;\"> $data <br>n\";
  34.  
  35. echo \" <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"480\">n\";
  36. echo \" <tr>n\";
  37. echo \" <td align=\"center\" width=\"480\">n\";
  38. echo \"   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"450\">n\";
  39. echo \"    <tr>n\";
  40. echo \"     <td align=\"center\" width=\"450\">n\";
  41. echo \"      <DIV ALIGN=\"justify\">n\";
  42. echo \"<font style=\"font-family: Verdana; font-size: 10px; color: gray;\">n\";
  43. echo \"$zawartosc_p n\";
  44. echo \"            </div>n\";
  45. echo \"          </td>n\";
  46. echo \"        </tr>n\";
  47. echo \"     </table>n\";
  48. echo \" </td>n\";
  49. echo \" </tr>n\";
  50. echo \" <tr>n\";
  51. echo \" <td align=\"left\" with\"480\">n\";
  52. echo \" &nbsp;<a target=\"blank\" href=\"index.php?action=view_r&id_news=$id_news\"><font style=\"font-family: Verdana; font-size: 9px;\"><i>Wiecej</i></a><br>n\";
  53. if(!$edit_n == 0) {
  54. echo \" &nbsp;&nbsp;&nbsp;<font style=\"font-family: Verdana; font-size: 9px;\"><i>Edytowano $edit_n razy</i><br>n\";
  55. }
  56. echo \" </td>n\";
  57. echo \" </tr>n\";
  58. echo \" </table>n\";
  59.  
  60. echo \"<center>n\";
  61. echo \"<img src=\"layout/l.jpg\">n\";
  62. echo \"</center>n\";
  63. echo \"<br>n\";
  64. }
  65. echo \"</td>n\";
  66. echo \"</TR>n\";
  67. echo \"</TABLE>n\";
  68. html_footer();
  69.  
  70. function view_r() {
  71.     global $id_news;
  72.     $query = \"SELECT news_headline, add_ndate, autor, news_contents, more, edit_num FROM n
  73. ws WHERE news_id = '$id_news'\";
  74.     $wynik = mysql_query($query);
  75.     if(!$wynik) error_message(sql_error());
  76.     $q_data = mysql_fetch_array($wynik);
  77.  
  78.     $naglowek = $q_data[\"news_headline\"];
  79.     $data = $q_data[\"add_ndate\"];
  80.     $autor = $q_data[\"autor\"];
  81.     $zawartosc_p = $q_data[\"news_contents\"];
  82.     $zawartosc_k = $q_data[\"more\"];
  83.     $edit_n = $q_data[\"edit_num\"];
  84.  
  85.     html_header();
  86. echo \"<TR>n\";
  87. echo \"<TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>News</b></center></TD>n\";
  88. echo \"</TR>n\";
  89. echo \"</table>n\";
  90. echo \"<TABLE BORDER=\"0\" cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1200\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">n\";
  91. echo \" <TR>n\";
  92. echo \"  <TD valign=\"top\" align=\"left\" bgcolor=\"#414141\" colspan=\"3\">n\";
  93. echo \"<br>n\";
  94.  
  95. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9pt; color: gray;\"><b> $naglowek </b><br>n\";
  96. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9px; color: darkgray;\"> $data <br>n\";
  97.  
  98. echo \" <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"480\">n\";
  99. echo \" <tr>n\";
  100. echo \" <td align=\"center\" width=\"480\">n\";
  101. echo \"   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"450\">n\";
  102. echo \"    <tr>n\";
  103. echo \"     <td align=\"center\" width=\"450\">n\";
  104. echo \"      <DIV ALIGN=\"justify\">n\";
  105. echo \"<font style=\"font-family: Verdana; font-size: 10px; color: gray;\">n\";
  106. echo \"$zawartosc_p  <br><br>n\";
  107. echo \"$zawartosc_k n\";
  108. echo \"            </div>n\";
  109. echo \"          </td>n\";
  110. echo \"        </tr>n\";
  111. echo \"     </table>n\";
  112. echo \" </td>n\";
  113. echo \" </tr>n\";
  114. if(!$edit_n == 0) {
  115. echo \" <tr>n\";
  116. echo \" <td align=\"left\" with\"480\">n\";
  117. echo \" &nbsp;&nbsp;&nbsp;<font style=\"font-family: Verdana; font-size: 9px;\"><i>Edytowano $edit_n razy</i><br>n\";
  118. echo \" </td>n\";
  119. echo \" </tr>n\";
  120. }
  121. echo \" </table>n\";
  122.  
  123. echo \"<center>n\";
  124. echo \"<img src=\"layout/l.jpg\">n\";
  125. echo \"</center>n\";
  126. echo \"<br>n\";
  127. echo \"</td>n\";
  128. echo \"</TR>n\";
  129. echo \"</TABLE>n\";
  130. html_footer();
  131.  
  132.  
  133.  
  134. }
  135.  
  136. switch($action) {
  137.     case \"view_r\";
  138.     view_r();
  139.     break;
  140. }
  141.  
  142. ?>



Prosze o pomoc.

Pzdr

Ten post edytował Majcok12 20.10.2004, 18:13:40
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Majcok12
post
Post #2





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Cytat(ARJ @ 2004-10-19 13:19:45)
skrypt dałeś niepełny ale chyba wiem o co chodzi. w środkowym kawałku kodu zaprezentowałeś link, link ten powinien być wstawiony w funkcje while z pierwszego kawałka. bo jeśli niejest to może dlatego jest taki błąd.
mam nadzieję że o to chodzi.


EH, sorry za zamieszanie. Dzieki postowi Fibolg'a sprawdzilem w bazie czy czasem id tego ostatniego newsa i pierwszego nie sa takie same i okazalo sie ze byly:P (ale juz takiej sytuacji nie bedzie, gdyz pole to ustawilem na UNIQUE).

Dzieki za wszystko.

------------------------------
Przy okzji zamiast robic nowy temat napisze tu to. Juz kiedys na forum webhelp.pl o tym pisalem ale rozwiazania prolemu nie otrzymalem. Otoz problem jest z skryptem logowania. Wpisuje dane, ktore zgadzaja sie z tymi ktore sa w bazie i mimo to skrypt generuje komunikat, ze "logowanie nie powiedlo sie ..."

pozniej kod skryptu:
  1. <?
  2. include(&#092;"common.php\");
  3. if(!session_is_registered($user_nick)) {
  4.     log_form();
  5.     exit;
  6. }
  7. else {
  8.     session_register(&#092;"user_nick\", \"user_password\");
  9.     $usernick = auth_u($user_nick, $user_password);
  10.     if(!$usernick) {
  11.         session_unregister(&#092;"user_nick\");
  12.         session_unregister(&#092;"user_password\");
  13.         echo &#092;"Logowanie nieudane.\" .
  14.             &#092;"Musisz podać poprawny nick oraz hasło. \" . 
  15.             &#092;"Spróboj jeszcze raz się zalogować. <br>n\";
  16.         echo &#092;"<a href=\"$PHP_SELF\">Logowanie</a><br>\";
  17.         exit;
  18.     }
  19.     else 
  20. global $id_polaczenia;
  21. $id_polaczenia = db_connect();
  22. function in_use($user_nick) {
  23.     global $user_tablename;
  24.  
  25.     $query = &#092;"SELECT user_nick FROM $user_tablename WHERE user_nick = '$user_nick'\";
  26.     $wynik = mysql_query($query);
  27.     if(!mysql_num_rows($wynik)) return 0;
  28.     else return 1;
  29. }
  30.  
  31. function reg_form() {
  32.  
  33. html_header();
  34. ?>
  35.  </TR>
  36.  <TR>
  37.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  38.  
  39.  </TR>
  40. </table>
  41. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  42.  <TR>
  43.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  44. <br>
  45. <form method=\"post\" enctype=\"multipart/form-data\" action=\"<?php echo $PHP_SELF ?>\">
  46. <input type=\"hidden\" name=\"action\" value=\"register\">
  47.  
  48.   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"95%\" height=\"70%\" align=\"center\" valign=\"top\">
  49.    <tr>
  50.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Nick:</th>
  51.     <td width=\"70%\">&nbsp; <input type=\"text\" size=\"20\" maxlength=\"20\" name=\"nick\" class=\"pollItem\"></td>
  52.    </tr> 
  53.    <tr>
  54.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Wybrane hasło:</th>
  55.     <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  56.    </tr>
  57.    <tr>
  58.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Powtórz hasło:</th>
  59.     <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword2\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  60.    </tr>
  61.    <tr>
  62.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Email:</th>
  63.     <td width=\"70%\">&nbsp; <input type=\"text\" name=\"usermail\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  64.    </tr>
  65.    <tr>
  66.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">O sobie:</th>
  67.     <td width=\"70%\">&nbsp;<textarea rows=\"5\" cols=\"40\" name=\"userprofile\" class=\"pollItem\"></textarea></td>
  68.    </tr>
  69.    <tr>
  70.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Sprzęt:</th>
  71.     <td width=\"70%\">&nbsp; <input type=\"text\" name=\"userhardware\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  72.    </tr>
  73.    <tr>
  74.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Admin:</th>
  75.     <td width=\"70%\">&nbsp; <select name=\"admin\" size=1 class=\"pollItem\">
  76.     <option selected value=\"NIE\">NIE</option>
  77.     <option value=\"TAK\">TAK</option>
  78.     </select>
  79.     </td>
  80.    </tr>
  81.    <tr>
  82.     <th width=\"30%\" colspan=\"2\" NOWRAP>
  83.     <input type=\"submit\" class=\"pollButton\" value=\"Rejestruj\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\">
  84.     <input type=\"reset\" class=\"pollButton\" value=\"Wyczysc\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\"></th>
  85.    </tr>
  86.   </table>
  87. </table>
  88.  </form>
  89. <?php
  90.     html_footer();
  91. }
  92.  
  93. function register_user() {
  94.     global $id_polaczenia;
  95.     global $nick, $userpassword, $userpassword2, $usermail, $userprofile, $userhardware, $admin;
  96.     global $default_db, $user_tablename;
  97.     $awatar = &#092;"obrazki/users/none.jpg\";
  98.  
  99.     mailcheck($usermail);
  100.     if(empty($userprofile)) error_message(&#092;"Brak komentarza!\");
  101.     if(empty($usermail)) error_message(&#092;"Brak adresu email!\");
  102.     if(empty($nick)) error_message(&#092;"Brak nicku!\");
  103.     if(empty($userpassword)) error_message(&#092;"Brak hasla!\");
  104.     if(empty($userpassword2)) error_message(&#092;"Musisz powtórzyć hasło!\");
  105.     if($userpassword!=$userpassword2)
  106.         error_message(&#092;"Podane hasła nie są identyczne\");
  107.  
  108.     if(in_use($nick)) 
  109.         error_message(&#092;"Wybrany nick jest już zajęty, proszę wybrać inny\");
  110.  
  111.     $query = &#092;"INSERT INTO users VALUES(NULL, '$nick', password('$userpassword'), '$usermail', '$userprofile', curdate(), NULL, '$userhardware', '$awatar', '$admin')\";
  112.  
  113.     $wynik = mysql_query($query);
  114.     if(!$wynik) error_message(sql_error());
  115.  
  116.     html_header();
  117. ?>
  118.  <TR>
  119.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  120.  
  121.  </TR>
  122. </table>
  123. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  124.  <TR>
  125.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  126. <br>
  127. <font style=\"font-family: Verdana; font-size: 9pt; color: gray;\"><b>Użytkownik <?php echo $nick ?> został zarejestrowany</b><br>
  128.  
  129.  </tr>
  130. </table>
  131. <?php 
  132.      html_footer();
  133. }
  134.  
  135. switch($action) {
  136.     case &#092;"register\":
  137.         register_user();
  138.     break;
  139.     default:
  140.         reg_form();
  141.     break;
  142. }
  143. }
  144.  
  145. function auth_u($user_nick, $user_password) {
  146.     global $id_polaczenia;
  147.     $id_polaczenia = db_connect();
  148.     $query = &#092;"SELECT user_nick FROM users WHERE user_nick = '$user_nick' AND user_pass = '$user_password' AND admin = 'TAK'\";
  149.  
  150.     $wynik = mysql_query($query);
  151.         if(!mysql_num_rows($wynik)) return 0;
  152.     else {
  153.         $query_data = mysql_fetch_row($wynik);
  154.         return $query_data[1];
  155.     }    
  156. }
  157. ?>



Wersja druga sesji (i gdy uruchamiam skrypt w wersji ponizej, juz nie pisze ze logowanie nie powiodlo sie, tylko zawsze ponownie wyswietla mi formularz logowania):
  1. <?
  2. include(&#092;"common.php\");
  3. if(!$_SESSION['user_nick']) { 
  4. log_form(); 
  5. exit; 
  6. }
  7. else {
  8. $_SESSION['user_nick\"\"user_password'];
  9. $usernick = auth_u($user_nick, $user_password);
  10. if(!$usernick) {
  11. unset($_SESSION['user_nick']);
  12. unset($_SESSION['user_password']);
  13. echo &#092;"Logowanie nieudane.\" .
  14. &#092;"Musisz podać poprawny nick oraz hasło. \" . 
  15. &#092;"Spróboj jeszcze raz się zalogować. <br>n\";
  16. echo &#092;"<a href=\"$PHP_SELF\">Logowanie</a><br>\";
  17. }
  18. else 
  19. ....
  20. ?>


Ten post edytował Majcok12 19.10.2004, 16:14:38
Go to the top of the page
+Quote Post

Posty w temacie
- Majcok12   [php/mysql] problem z skryptem logowania   16.10.2004, 21:30:44
- - ARJ   więc tak zaczne od drobnej porady: po co utrudnias...   16.10.2004, 21:40:11
- - Majcok12   Lista newsow. A jak by to wygladalo, gdy na stroni...   16.10.2004, 21:51:27
- - ARJ   jak pokazujesz newsa to dajesz np. w jego tytule l...   16.10.2004, 22:19:39
- - Majcok12   Nie wiem, czy dobrze zrozumialem, Zrobilem to tak:...   18.10.2004, 21:04:59
- - Fibolg   Prawdopodobnie masz akurat ustawioną zmienną ID na...   19.10.2004, 07:16:32
- - ARJ   skrypt dałeś niepełny ale chyba wiem o co chodzi. ...   19.10.2004, 12:19:45
- - Majcok12   Cytat(ARJ @ 2004-10-19 13:19:45)skrypt dałeś ...   19.10.2004, 12:53:46
- - ARJ   zaglądnij w ten topic http://forum.php.pl/index.ph...   19.10.2004, 22:40:12
- - Majcok12   Wykorzystalem twoj pomysl, ale pewnie cos zle zrob...   20.10.2004, 09:10:25
- - ARJ   twój kod jest bardziej zaawansowany niż mój. po dł...   20.10.2004, 13:02:43
- - Majcok12   RE: [php/mysql] problem z skryptem logowania   20.10.2004, 17:58:05
- - ARJ   Cytat(Majcok12 @ 2004-10-20 18:58:05)57 [PHP]...   20.10.2004, 19:48:45
- - Majcok12   Zmienilem skrypt tak jak napisales i to samo. Pro...   20.10.2004, 20:20:38
- - ARJ   a jeśli dasz [PHP] pobierz, plaintext <?  ...   20.10.2004, 21:24:21
- - Majcok12   Cytat(ARJ @ 2004-10-20 22:24:21)a jeśli dasz ...   21.10.2004, 20:24:46
- - ARJ   tylko po co wracać na tą stronę? ona loguje tylko ...   22.10.2004, 15:46:15
- - Majcok12   Zapomnialem napisac. Chociaz po podaniu poprawnych...   23.10.2004, 14:36:50


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: 14.10.2025 - 19:42