Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][PHP]Wyniki., Problemy z wyświetleniem wyniku.
assasin
post
Post #1





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


Witam, mam mały problem z wyświetleniem wyniku na stronie:) w php jestem mniej niż początkujący... a więc tak:
Zainstalowałem sobie cms-a WordPress, utworzyłem nową podstrone.. w której chce umieścić rejestracje..
Poniższa rejestracja działa poprawnie, wyświetla dobry wynik bez naruszenia strony:)
  1.  
  2.  
  3. <?php
  4. /*Config*/
  5.  
  6. $realmd = array(
  7. 'db_host'=> '', //ip of db realm
  8. 'db_username' => '',//realm user
  9. 'db_password' => '',//realm password
  10. 'db_name'=> 'realmd',//realm db name
  11. );
  12.  
  13.  
  14. ///////////////Start script//////////////////
  15.  
  16. /*
  17. Function name: CHECK FOR SYMBOLS
  18. Description: return TRUE if matches. ( True = OK ) ( False = NOT OK)
  19. */
  20. function check_for_symbols($string){
  21. $len=strlen($string);
  22. $alowed_chars="abcdefghijklmnopqrstuvwxyzAŚA¸AYABCDEFGHIJKLMNOPQRSTUVWXYZA†A~A…";
  23. for($i=0;$i<$len;$i++)if(!strstr($alowed_chars,$string[$i]))return TRUE;
  24. return FALSE;
  25.  
  26. }
  27. /*
  28. Function name: OUTPUT USERNAME:PASSWORD AS SHA1 crypt
  29. Description: obious.
  30. */
  31. function sha_password($user,$pass){
  32. $user = strtoupper($user);
  33. $pass = strtoupper($pass);
  34.  
  35. return SHA1($user.':'.$pass);
  36. }
  37.  
  38. if ($_POST['registration']){
  39. /*Connect and Select*/
  40. $realmd_bc_new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]);
  41. $selectdb = mysql_select_db($realmd[db_name],$realmd_bc_new_connect);
  42. if (!$realmd_bc_new_connect || !$selectdb){
  43. echo "Could NOT connect to db, please check the config part of the file!";
  44. }
  45.  
  46. /*Checks*/
  47. $username = $_POST['username'];
  48. $password = sha_password($username,$_POST['password']);
  49.  
  50. $qry_check_username = mysql_query("SELECT username FROM `account` WHERE username='$username'");
  51.  
  52. if (check_for_symbols($_POST[password]) == TRUE || check_for_symbols($username) == TRUE || mysql_num_rows($qry_check_username) != 0){
  53. echo "Error with creating account, might already be in use or your username / password has invalid symbols in it.";
  54. }else{
  55. mysql_query("INSERT INTO account (username,sha_pass_hash) VALUES
  56. ('$username','$password')");// Insert into database.
  57. echo "Account created.";
  58. }
  59.  
  60.  
  61. }else{
  62. ///////////////Stop script, Start HTML//////////////////
  63. ?>
  64.  
  65.  
  66. <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
  67.  
  68. Username <input type="text" name="username">
  69.  
  70. Password <input type="password" name="password">
  71.  
  72. <input type="submit" name="registration">
  73. </form>
  74.  
  75.  
  76. <?php
  77. // Do not remove this;)
  78. }
  79. ?>


Tylko ja bym chciał umieścić tą rejestracje:

  1. <?php
  2.  
  3. // Configuration.
  4. // Realm database.
  5. $r_db = "realmd";
  6. // IP (and port).
  7. $ip = "127.0.0.1:3306";
  8. // Username.
  9. $user = "trinity";
  10. // Password.
  11. $pass = "trinity";
  12. // Site title.
  13. $title = "Registration Form";
  14. $title2 = "Some Server";
  15. // End config.
  16.  
  17. $page = '<?xml version="1.0" encoding="utf-8" ?>
  18. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  19. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  20. <head>
  21. <title>' . $title . '</title>
  22. </head>
  23. <body style="background-color:black;color:yellow;font-family:verdana;">
  24. <form method="post" action="' . $_SERVER["SCRIPT_NAME"] . '">
  25. <p style="text-align:center;">
  26. <strong>' . $title2 . ' - ' . $title . '</strong>
  27. <br /><br /><br />
  28. Username:
  29. <br /><input name="username" type="text" maxlength="14" /><br />
  30. Password:
  31. <br /><input name="password" type="password" maxlength="12" /><br />
  32. Email:
  33. <br /><input name="email" type="text" maxlength="50" />
  34. <br /><input name="tbc" type="checkbox" checked="checked" /> TBC<br /><br /><br />
  35. <button type="submit">Submit</button>
  36. </p>
  37. </form>
  38. </body>
  39. </html>';
  40.  
  41. function error_s ($text) {
  42. echo("<p style=\"background-color:black;color:yellow;font-family:verdana;\">" . $text);
  43. echo("<br /><br /><a style=\"color:orange;\" href=\"" . $_SERVER["SCRIPT_NAME"] . "\">Go back...</a></p>");
  44. };
  45.  
  46. $user_chars = "#[^a-zA-Z0-9_\-]#";
  47. $email_chars = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
  48.  
  49. $con = @mysql_connect($ip, $user, $pass);
  50. if (!$con) {
  51. error_s("Unable to connect to database: " . mysql_error());
  52. };
  53.  
  54. if (!empty($_POST)) {
  55. if ((empty($_POST["username"]))||(empty($_POST["password"]))||(empty($_POST["email"]))||(empty($_POST["tbc"])) ) {
  56. error_s("You did not enter all the required information.");
  57. exit();
  58. } else {
  59. $username = strtoupper($_POST["username"]);
  60. $password = strtoupper($_POST["password"]);
  61. $email = strtoupper($_POST["email"]);
  62. if (strlen($username) < 5) {
  63. error_s("Username too short.");
  64. exit();
  65. };
  66. if (strlen($username) > 14) {
  67. error_s("Username too long.");
  68. exit();
  69. };
  70. if (strlen($password) < 8) {
  71. error_s("Password too short.");
  72. exit();
  73. };
  74. if (strlen($password) > 12) {
  75. error_s("Password too long.");
  76. exit();
  77. };
  78. if (strlen($email) < 15) {
  79. error_s("Email was too short.");
  80. exit();
  81. };
  82. if (strlen($email) > 50) {
  83. error_s("Email was too long.");
  84. exit();
  85. };
  86. if (preg_match($user_chars,$username)) {
  87. error_s("Username contained illegal characters.");
  88. exit();
  89. };
  90. if (preg_match($user_chars,$password)) {
  91. error_s("Password contained illegal characters.");
  92. exit();
  93. };
  94. if (!preg_match($email_chars,$email)) {
  95. error_s("Email was in an incorrect format.");
  96. exit();
  97. };
  98. if ($_POST['tbc'] != "on") {
  99. $tbc = "0";
  100. } else {
  101. $tbc = "1";
  102. };
  103. $username = mysql_real_escape_string($username);
  104. $password = mysql_real_escape_string($password);
  105. $email = mysql_real_escape_string($email);
  106. $qry = @mysql_query("select username from " . mysql_real_escape_string($r_db) . ".account where username = '" . $username . "'", $con);
  107. if (!$qry) {
  108. error_s("Error querying database: " . mysql_error());
  109. };
  110. if ($existing_username = mysql_fetch_assoc($qry)) {
  111. foreach ($existing_username as $key => $value) {
  112. $existing_username = $value;
  113. };
  114. };
  115. $existing_username = strtoupper($existing_username);
  116. if ($existing_username == strtoupper($_POST['username'])) {
  117. error_s("That username is already taken.");
  118. exit();
  119. };
  120. unset($qry);
  121. $qry = @mysql_query("select email from " . mysql_real_escape_string($r_db) . ".account where email = '" . $email . "'", $con);
  122. if (!$qry) {
  123. error_s("Error querying database: " . mysql_error());
  124. };
  125. if ($existing_email = mysql_fetch_assoc($qry)) {
  126. foreach ($existing_email as $key => $value) {
  127. $existing_email = $value;
  128. };
  129. };
  130. if ($existing_email == $_POST['email']) {
  131. error_s("That email is already in use.");
  132. exit();
  133. };
  134. unset($qry);
  135. $sha_pass_hash = sha1(strtoupper($username) . ":" . strtoupper($password));
  136. $register_sql = "insert into " . mysql_real_escape_string($r_db) . ".account (username, sha_pass_hash, email, expansion) values (upper('" . $username . "'),'" . $sha_pass_hash . "','" . $email . "','" . $tbc . "')";
  137. $qry = @mysql_query($register_sql, $con);
  138. if (!$qry) {
  139. error_s("Error creating account: " . mysql_error());
  140. };
  141. echo("Account successfully created.");
  142. exit();
  143. };
  144. } else {
  145. echo($page);
  146. };
  147.  
  148. ?>


A w tym wypadku, strona rozsypuje się;/ po wyświetleniu wyniku... Jaka modyfikacja sprawiał by że strona poprawnie by działała.. pozdrawiam.
Go to the top of the page
+Quote Post
2 Stron V   1 2 >  
Start new topic
Odpowiedzi (1 - 19)
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Zarówno die() jak i exit() zatrzymują wykonywanie skryptu. Nie należy ich zatem stosować notorycznie, a tylko w wyjątkowych przypadkach. Alternatywą jest używanie bloku
  1. if(warunek) {
  2. // kod do wykonania
  3. } elseif(inny warunek) {
  4. // inny kod do wykonania
  5. } else {
  6. // brak warunków
  7. // kod do wykonania
  8. }
Go to the top of the page
+Quote Post
assasin
post
Post #3





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


Ale co to ma się do wyświetlania wyniku?
Zastosowałem tą regułę:

  1. if (strlen($username) < 5) {
  2. error_s("Username too short.");
  3.  
  4.  
  5. } elseif (strlen($username) > 14) {
  6. error_s("Username too long.");
  7.  
  8.  
  9. } else { (strlen($password) < 8)
  10. error_s("Password too short.");
  11.  
  12. }
  13. if (strlen($password) > 12) {
  14. error_s("Password too long.");
  15.  
  16. };


no i
Parse error: syntax error, unexpected T_ELSE in.... w
error_s("Password too short.");
Go to the top of the page
+Quote Post
MateuszS
post
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%)
-----


Co za konstrukcja... w jakiej wersji PHP takie cuś wprowadzili?

  1. } else { (strlen($password) < 8)


--------------------
O! Zimniok :P
Go to the top of the page
+Quote Post
assasin
post
Post #5





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


No tak, poprawiłem ale co to ma do wyświetlania się wyniku?
Strona po stworzeniu konta powinna tak wyglądać:

a jest tak:)


Ten post edytował assasin 5.04.2010, 21:18:56
Go to the top of the page
+Quote Post
mortus
post
Post #6





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Przede wszystkim określ, co według Ciebie jest wynikiem.

Albo opisz dokładniej, co jest nie tak na tym drugim obrazku.
Go to the top of the page
+Quote Post
assasin
post
Post #7





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


No właśnie.. wynikiem dla mnie jest to co wyświetliło mi się po zakończeniu pracy skryptu:)
Na 2-gim obrazku widać że strona się rozleciała tzn: nie ma menu(sidebar), stopki (footer), i uwaliło trochę głównej strony (single)... coś nie tak z wyświetlaniem wyniku.
Go to the top of the page
+Quote Post
mortus
post
Post #8





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Niestety niewiele mogę Ci pomóc mając tylko skrypt rejestracji. Podejrzewam, że ten plik jest wstawiany za pomocą include do pliku, który zawiera layout strony, ale to tylko moje przypuszczenia. Najlepiej wklej tutaj kod pliku odpowiedzialnego za wygląd strony i aktualny kod pliku odpowiedzialnego za rejestrację.
Go to the top of the page
+Quote Post
assasin
post
Post #9





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


Nie, nie includuje rejestracji do pliku z wyglądem strony:) wszystko jest w jednym:

  1. <?php define('WP_USE_THEMES', false); require('./wp-blog-header.php'); get_header(); ?>
  2. <?php get_header(); ?>
  3.  
  4. <div id="container">
  5. <div id="left-div">
  6. <div id="left-inside">
  7. <?php if (have_posts()) : ?>
  8. <?php while (have_posts()) : the_post(); ?>
  9. <!--Start Post-->
  10. <span class="single-entry-titles" style="margin-top: 18px;"></span>
  11. <div class="post-wrapper">
  12.  
  13.  
  14.  
  15.  
  16.  
  17. <!--
  18. ///////////////////////////////////////////////////////////////////////
  19. // //
  20. // Skrypt rejestracyjny kompatybilny z bazą MySQL //
  21. // Dostosowany do emulatorów MaNGOS oraz TrinityCore //
  22. // //
  23. // Wersja 3.2.2a //
  24. // //
  25. // Kod udostępniony na licencji GNU General Public License v3.0 //
  26. // //
  27. // Autor: Michalo <michalo2882@gmail.com> //
  28. // //
  29. ///////////////////////////////////////////////////////////////////////
  30. -->
  31.  
  32. <html>
  33.  
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" >
  36. </head>
  37.  
  38. <body>
  39.  
  40. <?php
  41.  
  42. // Configuration.
  43. // Realm database.
  44. $r_db = "";
  45. // IP (and port).
  46. $ip = "128124124:3306";
  47. // Username.
  48. $user = "s";
  49. // Password.
  50. $pass = "";
  51. // Site title.
  52. $title = "Registration Form";
  53. $title2 = "Some Server";
  54. // End config.
  55.  
  56. $page = '<?xml version="1.0" encoding="utf-8" ?>
  57. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  58. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  59. <head>
  60. <title>' . $title . '</title>
  61. </head>
  62. <body style="background-color:black;color:yellow;font-family:verdana;">
  63. <form method="post" action="' . $_SERVER["SCRIPT_NAME"] . '">
  64. <p style="text-align:center;">
  65. <strong>' . $title2 . ' - ' . $title . '</strong>
  66. <br /><br /><br />
  67. Username:
  68. <br /><input name="username" type="text" maxlength="14" /><br />
  69. Password:
  70. <br /><input name="password" type="password" maxlength="12" /><br />
  71. Email:
  72. <br /><input name="email" type="text" maxlength="50" />
  73. <br /><input name="tbc" type="checkbox" checked="checked" /> TBC<br /><br /><br />
  74. <button type="submit">Submit</button>
  75. </p>
  76. </form>
  77. </body>
  78. </html>';
  79.  
  80. function error_s ($text) {
  81. echo("<p style=\"background-color:black;color:yellow;font-family:verdana;\">" . $text);
  82. echo("<br /><br /><a style=\"color:orange;\" href=\"" . $_SERVER["SCRIPT_NAME"] . "\">Go back...</a></p>");
  83. };
  84.  
  85. $user_chars = "#[^a-zA-Z0-9_\-]#";
  86. $email_chars = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
  87.  
  88. $con = @mysql_connect($ip, $user, $pass);
  89. if (!$con) {
  90. error_s("Unable to connect to database: " . mysql_error());
  91. };
  92.  
  93. if (!empty($_POST)) {
  94. if ((empty($_POST["username"]))||(empty($_POST["password"]))||(empty($_POST["email"]))||(empty($_POST["tbc"])) ) {
  95. error_s("You did not enter all the required information.");
  96. exit();
  97. } else {
  98. $username = strtoupper($_POST["username"]);
  99. $password = strtoupper($_POST["password"]);
  100. $email = strtoupper($_POST["email"]);
  101. if (strlen($username) < 5) {
  102. error_s("Username too short.");
  103.  
  104.  
  105. } elseif (strlen($username) > 14) {
  106. error_s("Username too long.");
  107.  
  108.  
  109. } else {
  110. error_s("Password too short.");
  111.  
  112. }
  113. if (strlen($password) > 12) {
  114. error_s("Password too long.");
  115.  
  116. };
  117. if (strlen($email) < 15) {
  118. error_s("Email was too short.");
  119.  
  120. };
  121. if (strlen($email) > 50) {
  122. error_s("Email was too long.");
  123.  
  124. };
  125. if (preg_match($user_chars,$username)) {
  126. error_s("Username contained illegal characters.");
  127.  
  128. };
  129. if (preg_match($user_chars,$password)) {
  130. error_s("Password contained illegal characters.");
  131.  
  132. };
  133. if (!preg_match($email_chars,$email)) {
  134. error_s("Email was in an incorrect format.");
  135. exit();
  136. };
  137. if ($_POST['tbc'] != "on") {
  138. $tbc = "0";
  139. } else {
  140. $tbc = "1";
  141. };
  142. $username = mysql_real_escape_string($username);
  143. $password = mysql_real_escape_string($password);
  144. $email = mysql_real_escape_string($email);
  145. $qry = @mysql_query("select username from " . mysql_real_escape_string($r_db) . ".account where username = '" . $username . "'", $con);
  146. if (!$qry) {
  147. error_s("Error querying database: " . mysql_error());
  148. };
  149. if ($existing_username = mysql_fetch_assoc($qry)) {
  150. foreach ($existing_username as $key => $value) {
  151. $existing_username = $value;
  152. };
  153. };
  154. $existing_username = strtoupper($existing_username);
  155. if ($existing_username == strtoupper($_POST['username'])) {
  156. error_s("That username is already taken.");
  157. exit();
  158. };
  159. unset($qry);
  160. $qry = @mysql_query("select email from " . mysql_real_escape_string($r_db) . ".account where email = '" . $email . "'", $con);
  161. if (!$qry) {
  162. error_s("Error querying database: " . mysql_error());
  163. };
  164. if ($existing_email = mysql_fetch_assoc($qry)) {
  165. foreach ($existing_email as $key => $value) {
  166. $existing_email = $value;
  167. };
  168. };
  169. if ($existing_email == $_POST['email']) {
  170. error_s("That email is already in use.");
  171. exit();
  172. };
  173. unset($qry);
  174. $sha_pass_hash = sha1(strtoupper($username) . ":" . strtoupper($password));
  175. $register_sql = "insert into " . mysql_real_escape_string($r_db) . ".account (username, sha_pass_hash, email, expansion) values (upper('" . $username . "'),'" . $sha_pass_hash . "','" . $email . "','" . $tbc . "')";
  176. $qry = @mysql_query($register_sql, $con);
  177. if (!$qry) {
  178. error_s("Error creating account: " . mysql_error());
  179. };
  180. echo("Account successfully created.");
  181. exit();
  182. };
  183. } else {
  184. echo($page);
  185. };
  186.  
  187. ?>
  188.  
  189.  
  190. </a></h1>
  191. <div style="clear: both;"></div>
  192.  
  193.  
  194.  
  195.  
  196.  
  197. </div>
  198. <?php endwhile; ?>
  199. <!--End Post-->
  200. <?php else : ?>
  201. <!--If no results are found-->
  202. <h1>No Results Found</h1>
  203. <p>The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.</p>
  204. <!--End if no results are found-->
  205. <?php endif; ?>
  206. </div>
  207. </div>
  208. <!--Begin Sidebar-->
  209. <?php get_sidebar(); ?>
  210. <!--End Sidebar-->
  211. <!--Begin Footer-->
  212. <?php get_footer(); ?>
  213. <!--End Footer-->
  214. </body>
  215. </html>
  216. Nie działająca rejestracja:

Cytat


Działająca:
Cytat



Go to the top of the page
+Quote Post
mortus
post
Post #10





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Nadal używasz exit. Jak już mówiłem exit powoduje zatrzymanie wykonywania skryptu. Zatem kod, który znajduje się pod exit nie zostanie w ogóle wykonany. Tym kodem u Ciebie jest fragment w HTML-u oraz funkcje odpowiedzialne m.in. za wstawienie sidebar i footer (odpowiednio get_sidebar() i get_footer()). Abyś zrozumiał przedstawię Ci przykład:
  1. <?php
  2. function wydrukuj() {
  3. echo 'breakpint';
  4. }
  5. wydrukuj();
  6. exit();
  7. wydrukuj();
  8. ?>
  9. <p>A tutaj jakiś akapit</p>
W powyższym przykładzie funkcja wydrukuj wykona się tylko raz w linii 5. Funkcja w linii 7 nie zostanie wykonana. Podobnie kod w linii 9 nie zostanie wyświetlony. Twoja strona wywali się wszędzie tam, gdzie spełnione będą określone warunki, a po nich występuje exit.
Go to the top of the page
+Quote Post
assasin
post
Post #11





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


Heh, bardzo ale to bardzo pomogłeśsmile.gif... tylko jest mały problem:) gdy usunę exit() to skrypt i tak wykona swoje działanie czyli np: zarejestruje pomimo tego że nie zostały spełnione warunki, jaką funkcją mam zastąpić exit??
Pozdrawiam.

Ten post edytował assasin 5.04.2010, 22:46:41
Go to the top of the page
+Quote Post
mortus
post
Post #12





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Nie zastąpisz funkcji exit. Możesz to zrobić tak:
  1. if (!empty($_POST)) {
  2. // dodajemy zmienną, która mówi, czy formularz został prawidłowo wypełniony
  3. // na początku przyjmujemy, że tak
  4. $isValid = true;
  5. if ((empty($_POST["username"]))||(empty($_POST["password"]))||(empty($_POST["email"]))||(empty($_POST["tbc"])) ) {
  6. error_s("You did not enter all the required information.");
  7. // jeśli jednak któreś pole jest puste, to formularz nie został prawidłowo wypełniony
  8. isValid = false;
  9. } else {
  10. $username = strtoupper($_POST["username"]);
  11. $password = strtoupper($_POST["password"]);
  12. $email = strtoupper($_POST["email"]);
  13. if (strlen($username) < 5) {
  14. error_s("Username too short.");
  15. // formularz nie został dobrze wypełniony również wtedy, gdy nazwa użytkownika jest zbyt krótka
  16. isValid = false;
  17. } elseif (strlen($username) > 14) {
  18. error_s("Username too long.");
  19.  
  20. // lub zbyt długa
  21. isValid = false;
  22.  
  23. }
  24. // itd,
  25. // ...
  26. if(isValid) {
  27. $sha_pass_hash = sha1(strtoupper($username) . ":" . strtoupper($password));
  28. $register_sql = "insert into " . mysql_real_escape_string($r_db) . ".account (username, sha_pass_hash, email, expansion) values (upper('" . $username . "'),'" . $sha_pass_hash . "','" . $email . "','" . $tbc . "')";
  29. $qry = @mysql_query($register_sql, $con);
  30. if (!$qry) {
  31. error_s("Error creating account: " . mysql_error());
  32. };
  33. echo("Account successfully created.");
  34. } else {
  35. echo $page;
  36. }
  37. };
  38. } else {
  39. echo($page);
  40. };
  41. ...

Go to the top of the page
+Quote Post
assasin
post
Post #13





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


Zdemotywowałeś mnie..
Go to the top of the page
+Quote Post
mortus
post
Post #14





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Cytat(assasin @ 5.04.2010, 23:58:08 ) *
Zdemotywowałeś mnie..
Dlaczego? Co to za problem. Po sprawdzeniu, czy formularz nie jest pusty deklarujesz zmienną isValid i ustawiasz jej wartość na true. Później zastępujesz wszystkie exit-y kodem isValid=false;, a na końcu, przed wysłaniem zapytania do bazy danych dokładasz jeden warunek. Naprawdę niewiele roboty.
Go to the top of the page
+Quote Post
assasin
post
Post #15





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


Wywala mi że: isValid = false;

Parse error: syntax error, unexpected '=' in
Go to the top of the page
+Quote Post
pedro84
post
Post #16





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

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


Kod
   isValid = false;


Eee, co to jest?


--------------------
Google knows the answer...
Go to the top of the page
+Quote Post
mortus
post
Post #17





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Zgubiłem prawie wszędzie znak $, ale o tej godzinie chyba mogłem ;P

Cytat(pedro84 @ 6.04.2010, 10:32:23 ) *
Kod
   isValid = false;


Eee, co to jest?

Instrukcja php bez "zgubionego" znaku $. Powinno być
  1. $isValid = false;


Ten post edytował mortus 6.04.2010, 09:34:16
Go to the top of the page
+Quote Post
assasin
post
Post #18





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


No właśnie też tak podejrzewałem, przecież zadeklarowaliśmy $isValid..

Hmm a tu:

  1. }
  2. $existing_username = strtoupper($existing_username);
  3. if ($existing_username == strtoupper($_POST['username'])) {
  4. error_s("That username is already taken.");
  5. $isValid = false;
  6. }
  7. unset($qry);
  8. $qry = @mysql_query("select email from " . mysql_real_escape_string($r_db) . ".account where email = '" . $email . "'", $con);
  9. } elseif (!$qry) {
  10. error_s("Error querying database: " . mysql_error());
  11. $isValid = false;
  12. }


W 9 linijce jest błąd.

Ten post edytował assasin 6.04.2010, 09:40:47
Go to the top of the page
+Quote Post
mortus
post
Post #19





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Bo tam nie ma być } elseif, tylko po prostu if z tym samym warunkiem.
Go to the top of the page
+Quote Post
assasin
post
Post #20





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

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


No i mam nadzieje ostatni problem w linijce 4.. Parse error: syntax error, unexpected '}, próbowałem wiele kombinacji winksmiley.jpg żadna nie poskutkowała.
Cytat
} else {
echo $page;
}
};
} else {
echo($page);
};
?>
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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 Aktualny czas: 20.08.2025 - 08:05