Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> dodawanie $error_msg po niedanym logowaniu
dirtyhustlaz
post
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 29.03.2012

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


Chcialbym dodac wiadomosc po nieudanym logowaniu, ale nie wiem jak zabardzo.

utowrzylem zmienna $error_msg i chcialem ja wyswietlic po nieudanym logowaiu tuz nad formularzem, ale nie dziala. Moze mi ktos z tym pomoc?

  1. <?php
  2.  
  3.  
  4.  
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7. $errors = array();
  8.  
  9.  
  10. if ($username&&$password)
  11. {
  12. $connect = mysql_connect("localhost","uo151818_fallena","pass1234") or die ("Could not connect");
  13. mysql_select_db ("uo151818_fallenangels") or die ("Could not find database");
  14.  
  15.  
  16. $query = mysql_query("SELECT * FROM users WHERE username ='$username'");
  17.  
  18. $numrows = mysql_num_rows($query);
  19. if ($numrows !=0)
  20. {
  21. while ($row =mysql_fetch_assoc($query))
  22. {
  23. $dbusername = $row['username'];
  24. $dbpassword = $row['password'];
  25. }
  26.  
  27. if ($username==$dbusername&&$password==$dbpassword)
  28. {
  29. echo header('Location: menu.php');
  30. $_SESSION['username']=$dbusername;
  31. }
  32. else
  33. echo header('Location:login.php');
  34. $error_msg = "Enter correct login and password.";
  35.  
  36. }
  37. }
  38.  
  39. ?>
  40. <html>
  41. <head>
  42. <meta charset="utf-8">
  43. <meta name="viewport" content="width=device-width, initial-scale=1">
  44. <title>.:Fallen Angels Tatto and Bodypiercing:.</title>
  45. <link rel="stylesheet" href="themes/blackandwhite.min.css" />
  46. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile.structure-1.3.1.min.css" />
  47. <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  48. <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
  49. </head>
  50. <body>
  51.  
  52. <div data-role="page" data-theme="a">
  53.  
  54. <div data-role="header">
  55. <h1>Fallen Angels</h1>
  56. <div data-role="navbar">
  57. <ul>
  58. <li><a href="index.php" data-transition="slide" data-icon="home" data-iconpos="left">Home Page</a></li>
  59.  
  60. </ul>
  61. </div><!-- /navbar -->
  62. </div><!-- /header -->
  63.  
  64. <div data-role="content" class="ui-hide-label">
  65. <h3> Login: </h3>
  66. <form action="login.php" method="post">
  67. <p><?php echo $error_msg; ?></p>
  68. <label for="username">Username:</label>
  69. <input type="text" name="username" id="username" value="" placeholder="Username"/></br>
  70. <label for="password">Password:</label>
  71. <input type="password" name="password" id="password" value="" placeholder="Password"/>
  72. <div data-role="controlgroup" data-type="horizontal" align="center">
  73. <input type="submit" value="Submit">
  74. <input type="reset" value="Reset">
  75. </div>
  76. <form>
  77. </div><!-- /content -->
  78.  
  79. <div data-role="footer" data-position="fixed">
  80. <h4>Fallen Angels 2013. All right reserved.</h4>
  81. </div><!-- /footer -->
  82. </div><!-- /page -->
  83. </body>
  84. </html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Wywal to:
echo header('Location:login.php');
toż jestes w login.php wiec nie przekierowuj na siebie samego bez potrzeby.


Poza tym nie robi się ECHO dla header :/
Go to the top of the page
+Quote Post
dirtyhustlaz
post
Post #3





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 29.03.2012

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


rzeczywiscie niepotrzebnie przekierowywalem na ta sama strone niepotrzebnie, ale nawet teraz nie wyswietla mi error msg
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




$error_msg = "Enter correct login and password.";
To ustawiasz dopiero gdy user poda poprawny login. A gdy poda niepoprawny to ci w ogole do tego miejsca nie dojdzie
Go to the top of the page
+Quote Post

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: 22.08.2025 - 19:38