Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][mysql] problem z logowaniem i bazą danych
mtskilla
post
Post #1





Grupa: Zarejestrowani
Postów: 76
Pomógł: 1
Dołączył: 17.01.2007

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


  1. <?php
  2. include "conn.inc.php";
  3. ?>
  4.  
  5.  
  6.  
  7. <?php print '<'.'?xml version="1.0" encoding="iso-8859-2"?'.'>'; ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  9. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10.  
  11. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  12. <head>
  13. <meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
  14. <title>php</title>
  15. <link href="style.css" type="text/css" rel="stylesheet" />
  16. </head>
  17. <body>
  18.  
  19.  
  20. <?php
  21.  
  22. if (isset($_POST['submit']) && $_POST['submit'] == "Zarejestruj") {
  23. if ($_POST['username'] != "" &&
  24. $_POST['password'] != "" &&
  25. $_POST['first_name'] != "" &&
  26. $_POST['last_name'] != "" ) {
  27.  
  28.  
  29. $query = "SELECT username FROM user_info".
  30. "WHERE username = '" . $_POST['username'] . "';";
  31.  
  32. $result = mysql_query($query)
  33. or die (mysql_error());
  34.  
  35. if (mysql_num_rows($result) != 0) {
  36.  
  37. ?>
  38.  
  39. Nazwa uzytkownika
  40. <?php echo $_POST['username']; ?> jest już używana. Proszę wybrac inna!
  41.  
  42. <form acrion="index.php" method="post">
  43. Nazwa kierownika: <input type="text" name="username" /><br />
  44. Haslo: <input type="password" name="password" value="<?php echo $_POST['password']; ?>" /><br />
  45. Imię: <input type="text" name="first_name" value="<?php echo $_POST['first_name']; ?>" /><br />  
  46. Nazwisko: <input type="text" name="last_name" value="<?php echo $_POST['last_name']; ?>" /><br /> 
  47. <input type="submit" name="submit" value="Zarejestruj" />  
  48. <input type="reset" value="Wyczysc" />
  49. </form>
  50.  
  51. <?php
  52. } else {
  53. $query= "INSERT INTO user_info (username, password, first_name, last_name)".
  54. "VALUES (
  55. '".$_POST['username']."', 
  56. (PASSWORD('".$_POST['password']."')),
  57. '".$_POST['first_name']."',
  58. '".$_POST['last_name']."')";
  59.  
  60.  
  61. $result = mysql_query($query)
  62. or die (mysql_error());
  63.  $_SESSION['user_logged'] = $_POST['username'];
  64.  $_SESSION['user_password'] = $_POST['password'];
  65. ?>
  66.  
  67.  <?php echo $_POST['first_name']."".$_POST['last_name']; ?> Zostal pomyslnie dodany jako kierownik.
  68.  
  69. <?php 
  70. header("Refresh: 5; URL=index.php");
  71. echo "Kierownik dodany." . " Za moment nastąpi przeniesienie na stronę glowną.<br />";
  72. die();
  73. }
  74. }else {
  75. ?>
  76.  
  77.  
  78. Należy wypelnic wszystkie pola!
  79.  
  80. <form acrion="admin.php" method="post">
  81. Nazwa kierownika: <input type="text" name="user" value="<?php echo $_POST['username']; ?>" /> <br />
  82. Haslo: <input type="password" name="password" value="<?php echo $_POST['password']; ?>" /> <br />
  83. Imię: <input type="text" name="first_name" value="<?php echo $_POST['first_name']; ?>" />  <br />  
  84. Nazwisko: <input type="text" name="last_name" value="<?php echo $_POST['last_name']; ?>" /> <br /> 
  85. <input type="submit" name="submit" value="Zarejestruj" />  
  86. <input type="reset" value="Wyczysc" />
  87. </form>
  88.  
  89. <?php
  90. }
  91. } else {
  92. ?>
  93.  
  94. Należy podac login, hasla, imienia oraz nazwiska kierownika.
  95.  
  96.  
  97. <form acrion="admin.php" method="post">
  98. Nazwa kierownika: <input type="text" name="username" /><br />
  99. Haslo: <input type="password" name="password" /><br />
  100. Imię: <input type="text" name="first_name" /><br />  
  101. Nazwisko: <input type="text" name="last_name" /><br /> 
  102. <input type="submit" name="submit" value="Zarejestruj" />  
  103. <input type="reset" value="Wyczysc" />
  104. </form>
  105.  
  106. <?php
  107. }
  108. ?>
  109.  
  110. </body>
  111. </html>

Problem polega na tym, ze zamiast dzialac wywala mi błąd Something is wrong in your syntax obok '= 'asdasd'' w linii 1. w bazie mam tabele user_info. HELP

Ten post edytował mtskilla 22.01.2007, 11:53:04
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mtskilla
post
Post #2





Grupa: Zarejestrowani
Postów: 76
Pomógł: 1
Dołączył: 17.01.2007

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


Wyświetla sie nazwa i haslo. Ale dzieki temu nareszcie widze w czym tkwi problem tak naprawde. nie chodzi o plik rejestracji - tak jak myslalem, ale o strone z logowaniem .. tam cos mam namieszane z ta sesją..
strona logowania:

  1. <?php
  2. include "conn.inc.php";  
  3. ?>
  4.  
  5. <?php
  6.  
  7. if (isset($_POST['submit'])) {
  8. $query = "SELECT username, password FROM user_info WHERE username = '".$_POST['username']."' AND password = (PASSWORD('".$_POST['password']."'))";
  9. $result = mysql_query($query)
  10. or die(mysql_error());
  11.  
  12. if (mysql_num_rows($result) == 1) {
  13. $_SESSION['user_logged'] = $_POST['password'];
  14. header ("Refresh:0; URL=".$_POST['redirect']. "");
  15. echo "Zostajesz przekierowany na oryginalną strone, której żądales!<br>";
  16. } else {
  17.  ?>
  18.  
  19.  
  20.  
  21.  
  22. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  23. <body>
  24.  
  25.  
  26.  
  27. Niepoprawny login lub haslo!<br />
  28. <form action="log.php" method="post">
  29. <input type="hidden" name="redirect" value="<?php echo $_POST['redirect'];?>">
  30. Login: <input type="text" name="username"><br />
  31. Haslo: <input type="password" name="password"><br /><br />
  32. <input type="submit" name="submit" value="Zaloguj">
  33. </form>
  34.  
  35.  
  36. </body>
  37. </html>
  38.  
  39.  
  40.  
  41. <?php
  42. }
  43. } else {
  44. if (isset($_GET['redirect'])){
  45. $redirect = $_GET['redirect'];
  46. } else {
  47. $redirect = "kierownik.php";
  48.  
  49. }
  50. ?>
  51.  
  52.  
  53. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  54. <body>
  55.  
  56.  
  57. Zaloguj się. Podając login i haslo.
  58. <form action="log.php" method="post">
  59. <input type="hidden" name="redirect" value="<?php echo $redirect;?>">
  60. Login: <input type="text" name="username"><br />
  61. Haslo: <input type="password" name="password"><br /><br />
  62. <input type="submit" name="submit" value="Zaloguj">
  63. </form>
  64.  
  65.  
  66. <?php
  67. }
  68. ?>
  69.  
  70.  
  71. </body>
  72. </html>


Nie wiem czy taka skladnia jest odpowiednia..
Go to the top of the page
+Quote Post

Posty w temacie


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: 12.10.2025 - 20:52