Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Wyświetlanie wiadomości ECHO
webfreak
post 31.03.2011, 16:14:28
Post #1





Grupa: Zarejestrowani
Postów: 77
Pomógł: 8
Dołączył: 29.03.2011
Skąd: Londyn

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


Witam posaidam skrypt logowania http://36i6.co.uk/admin gdzie wpisując złe dane logowania otwiera nową stronę z wiadomościa " Wrong username or password " czy ma ktoś pojęcie jak zrobić aby ta wiadomość wyświetlila się w miejcu gdzie teraz jest " sorry but you have to log in first " ?


--------------------
http://szkolahtml.pl
Go to the top of the page
+Quote Post
Mackos
post 31.03.2011, 16:16:10
Post #2





Grupa: Zarejestrowani
Postów: 362
Pomógł: 44
Dołączył: 10.06.2009

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


Jakbyś wkleił kod, byłoby nam łatwiej wink.gif


--------------------
WebLemon.pl - projektowanie stron www, reklama i PR w internecie - Adwords, Facebook.
Go to the top of the page
+Quote Post
sakul55
post 31.03.2011, 16:18:02
Post #3





Grupa: Zarejestrowani
Postów: 39
Pomógł: 4
Dołączył: 27.03.2011

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


cos takiego musisz zrobic:
  1. if(isset($_POST['submit'])){
  2.  
  3. //tutaj kod z pliku gdzie jest Wrong username or password
  4.  
  5. } else {
  6.  
  7. //tutaj kod z pliku z formularzem
  8. }


Ten post edytował sakul55 31.03.2011, 16:18:45
Go to the top of the page
+Quote Post
webfreak
post 31.03.2011, 17:15:57
Post #4





Grupa: Zarejestrowani
Postów: 77
Pomógł: 8
Dołączył: 29.03.2011
Skąd: Londyn

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


  1.  
  2. <?php
  3. $host="localhost"; // Host name
  4. $username="web230"; // Mysql username
  5. $password="y3"; // Mysql password
  6. $db_name="web230"; // Database name
  7. $tbl_name="members"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. // username and password sent from form
  14. $myusername=$_POST['myusername'];
  15. $mypassword=$_POST['mypassword'];
  16.  
  17. // To protect MySQL injection (more detail about MySQL injection)
  18. $myusername = stripslashes($myusername);
  19. $mypassword = stripslashes($mypassword);
  20. $myusername = mysql_real_escape_string($myusername);
  21. $mypassword = mysql_real_escape_string($mypassword);
  22.  
  23. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  24. $result=mysql_query($sql);
  25.  
  26. // Mysql_num_row is counting table row
  27. $count=mysql_num_rows($result);
  28. // If result matched $myusername and $mypassword, table row must be 1 row
  29.  
  30. if($count==1){
  31. // Register $myusername, $mypassword and redirect to file "login_success.php"
  32. session_register("myusername");
  33. session_register("mypassword");
  34. header("location:panel.php");
  35. }
  36. else {
  37. echo "Wrong Username or Password";
  38. }
  39. ?>
  40.  


--------------------
http://szkolahtml.pl
Go to the top of the page
+Quote Post
kadlub
post 31.03.2011, 17:29:14
Post #5





Grupa: Zarejestrowani
Postów: 548
Pomógł: 105
Dołączył: 4.06.2010

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


w tym else gdzie masz #
echo "Wrong Username or Password";
daj przekierowanie ze zmienną GET do tej strony co masz
" sorry but you have to log in first "
a na tej stronie daj
  1. if(isset($_GET['error'])){
  2. echo "Wrong Username or Password";
  3. }
  4.  
Go to the top of the page
+Quote Post
Mackos
post 31.03.2011, 18:14:46
Post #6





Grupa: Zarejestrowani
Postów: 362
Pomógł: 44
Dołączył: 10.06.2009

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


Proste jak nic wink.gif
Więc tak, na stronie głównej (tam gdzie jest panel logowania - nazwijmy ją index.php) zamień:
  1. <form action="checklogin.php" method="post">

na
  1. <form action="index.php" method="post">


I potem na zamym początku pliku wklej:
  1. <?php
  2. if($_POST['Submit']=="Login"){
  3. $host="localhost"; // Host name
  4. $username="web230"; // Mysql username
  5. $password="y3"; // Mysql password
  6. $db_name="web230"; // Database name
  7. $tbl_name="members"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. // username and password sent from form
  14. $myusername=$_POST['myusername'];
  15. $mypassword=$_POST['mypassword'];
  16.  
  17. // To protect MySQL injection (more detail about MySQL injection)
  18. $myusername = stripslashes($myusername);
  19. $mypassword = stripslashes($mypassword);
  20. $myusername = mysql_real_escape_string($myusername);
  21. $mypassword = mysql_real_escape_string($mypassword);
  22.  
  23. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  24. $result=mysql_query($sql);
  25.  
  26. // Mysql_num_row is counting table row
  27. $count=mysql_num_rows($result);
  28. // If result matched $myusername and $mypassword, table row must be 1 row
  29.  
  30. if($count==1){
  31. // Register $myusername, $mypassword and redirect to file "login_success.php"
  32. session_register("myusername");
  33. session_register("mypassword");
  34. header("location:panel.php");
  35. }
  36. else {
  37. $blad="Wrong Username or Password";
  38. }
  39. }
  40. ?>

I na koniec w dowolnym miejscu strony (tam gdzie ma wyskakiwać błąd) wklej:
  1. <?php echo $blad; ?>

A plik checklogin można wywalić wink.gif

Ten post edytował Mackos 31.03.2011, 18:15:13


--------------------
WebLemon.pl - projektowanie stron www, reklama i PR w internecie - Adwords, Facebook.
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 - 06:11