Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

3 Stron V   1 2 3 >  
Reply to this topicStart new topic
> [PHP][MySQL]Rejestracja
jaca121212
post
Post #1





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Czy mógłby mi to ktoś poprawić tak aby skrypt działał poprawnie
  1. Rejestracja
  2. <form action="rejestracja.php" method="POST">
  3. Nazwa Użytkownika/login: <input type="text" name="login" /><br />
  4. Hasło: <input type="password" name="haslo" /><br />
  5. Powtórz hasło: <input type="password" name="haslo1" /><br />
  6. Adres E-mail: <input type="text" name="email" /> <br />
  7. <input type="submit" value="Zarejestruj się!!" /><br />
  8. <?php
  9. if(isset($_SESSION['blad1'])) echo $_SESSION['blad'];
  10. ?>

  1. <?php
  2.  
  3. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email'])))
  4. {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = @new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_erron!=0)
  12. {
  13. echo "Error: ".$polaczenie->connect_errno . "Opis: ". $polaczenie->connect_error;
  14. }
  15. else
  16. {
  17. $login = $_POST['login'];
  18. $haslo = $_POST['haslo'];
  19. $haslo1 = $_POST['haslo1'];
  20. $email = $_POST['email'];
  21.  
  22. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  23. $haslo = htmlentities($haslo, ENT_QUOTES, "UTF-8");
  24. $haslo = htmlentities($haslo1, ENT_QUOTES, "UTF-8");
  25. $haslo = htmlentities($email, ENT_QUOTES, "UTF-8");
  26.  
  27. if($resultat = @$polaczenie->query(
  28. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s', '%s')",
  29. mysqli_real_escape_string($polaczenie, $login),
  30. mysqli_real_escape_string($polaczenie, $haslo),
  31. mysqli_real_escape_string($polaczenie, $haslo1),
  32. mysqli_real_escape_string($polaczenie, $email))))
  33. {
  34. $ilu_userow = $resultat->num_rows;
  35. if($ilu_userow>0)
  36. {
  37. $_SESSION['zarejestrowany'] = true;
  38.  
  39.  
  40.  
  41. unset($_SESSION['blad']);
  42. $resultat->free_result();
  43. header('Location: index.php');
  44. }else
  45. {
  46. $_SESSION['blad'] = '<span style="color:red" >Nieprawidłowy Login lub Hasło! </span>';
  47. header('Location: index.php');
  48. }
  49. }
  50. $polaczenie->close();
  51. }
  52.  
  53. ?>

do tej pory jest taki błąd
  1. Notice: Undefined property: mysqli::$connect_erron IN C:\xampp\htdocs\rejestracja.php ON line 12


Ten post edytował jaca121212 6.04.2015, 08:04:49
Go to the top of the page
+Quote Post
Raito
post
Post #2





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Kod
if ($polaczenie->connect_erron!=0)
nie powinno być errno?

Ten post edytował Raito 6.04.2015, 08:22:33
Go to the top of the page
+Quote Post
jaca121212
post
Post #3





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


ale nawet nie zapisuje rekordów do bazy danych może źle jest napisana skladnia INSERT INTO

Ten post edytował jaca121212 6.04.2015, 10:44:51
Go to the top of the page
+Quote Post
Raito
post
Post #4





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


if($resultat = @$polaczenie->query( - usuń @
Go to the top of the page
+Quote Post
Turson
post
Post #5





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Zacznij od wywalenia wszystkich @ z kodu i Temat: Jak poprawnie zadac pytanie
Go to the top of the page
+Quote Post
jaca121212
post
Post #6





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Cytat(Raito @ 6.04.2015, 09:22:14 ) *
Kod
if ($polaczenie->connect_erron!=0)
nie powinno być errno?

jeśli usunę linie 12 to wyskakuje kolejny błąd z else w lini 16
Go to the top of the page
+Quote Post
Raito
post
Post #7





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


To nie usuwaj całej linii, tylko zamień if ($polaczenie->connect_erron!=0) na if ($polaczenie->connect_errno!=0).
Go to the top of the page
+Quote Post
jaca121212
post
Post #8





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Cytat(Raito @ 6.04.2015, 11:51:25 ) *
To nie usuwaj całej linii, tylko zamień if ($polaczenie->connect_erron!=0) na if ($polaczenie->connect_errno!=0).

jak zmieniłem na if ($polaczenie->connect_errno!=0) to zaden błąd się nie pojawił ale jest problem bo nie zamisuje się do bazy żaden rekord możliwe jest to że źle jest napisany skrypt dodawania usera do bazy teraz kod cały wygląda tak:
  1. <?php
  2.  
  3. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email'])))
  4. {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno!=0)
  12. {
  13. echo "Error: ".$polaczenie->connect_errno . "Opis: ". $polaczenie->connect_error;
  14. }
  15. else
  16. {
  17. $login = $_POST['login'];
  18. $haslo = $_POST['haslo'];
  19. $haslo1 = $_POST['haslo1'];
  20. $email = $_POST['email'];
  21.  
  22. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  23. $haslo = htmlentities($haslo, ENT_QUOTES, "UTF-8");
  24. $haslo = htmlentities($haslo1, ENT_QUOTES, "UTF-8");
  25. $haslo = htmlentities($email, ENT_QUOTES, "UTF-8");
  26.  
  27. if($resultat = $polaczenie->query(
  28. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s', '%s')",
  29. mysqli_real_escape_string($polaczenie, $login),
  30. mysqli_real_escape_string($polaczenie, $haslo),
  31. mysqli_real_escape_string($polaczenie, $haslo1),
  32. mysqli_real_escape_string($polaczenie, $email))))
  33. {
  34. $ilu_userow = $resultat->num_rows;
  35. if($ilu_userow>0)
  36. {
  37. $_SESSION['zarejestrowany'] = true;
  38.  
  39.  
  40.  
  41. unset($_SESSION['blad']);
  42. $resultat->free_result();
  43. header('Location: index.php');
  44. }else
  45. {
  46. $_SESSION['blad'] = '<span style="color:red" >Nieprawidłowy Login lub Hasło! </span>';
  47. header('Location: index.php');
  48. }
  49. }
  50. $polaczenie->close();
  51. }
  52.  
  53. ?>
Go to the top of the page
+Quote Post
Raito
post
Post #9





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


  1. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s', '%s')",
  2. mysqli_real_escape_string($polaczenie, $login),
  3. mysqli_real_escape_string($polaczenie, $haslo),
  4. mysqli_real_escape_string($polaczenie, $haslo1),
  5. mysqli_real_escape_string($polaczenie, $email))))


Próbujesz dodać do 4 wartości (`id`, `user`, `pass`, `email`) 5 wartości ('', '%s', '%s', '%s', '%s').
Go to the top of the page
+Quote Post
jaca121212
post
Post #10





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Cytat(Raito @ 6.04.2015, 12:04:46 ) *
  1. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s', '%s')",
  2. mysqli_real_escape_string($polaczenie, $login),
  3. mysqli_real_escape_string($polaczenie, $haslo),
  4. mysqli_real_escape_string($polaczenie, $haslo1),
  5. mysqli_real_escape_string($polaczenie, $email))))


Próbujesz dodać do 4 wartości (`id`, `user`, `pass`, `email`) 5 wartości ('', '%s', '%s', '%s', '%s').

ok już działa teraz pytanie jak sprawdzić czy hasła są takie same wpisane i jak kodować hasło md5 lub sh1 które kodowanie będzie najlepszę
Go to the top of the page
+Quote Post
Raito
post
Post #11





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Pobierasz z bazy zakodowane hasło i porównujesz z zakodowanym wpisanym hasłem.
Lepsze jest md5.
md5(cos);
Go to the top of the page
+Quote Post
jaca121212
post
Post #12





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


mam jeszcze problem bo jak wpisałem haslo to zamiast w bazie zapisac haslo zapisuje adres e mail w miejsce wpisania hasla tak wyglada to w bazie (IMG:http://www.iv.pl/images/33107898534028340754.png)
Go to the top of the page
+Quote Post
Turson
post
Post #13





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Cytat(Raito @ 6.04.2015, 12:15:27 ) *
Pobierasz z bazy zakodowane hasło i porównujesz z zakodowanym wpisanym hasłem.
Lepsze jest md5.
md5(cos);

Czemu lepsze md5? Już dawno zostało złamane. Lepsza opcja to hash+sól
Go to the top of the page
+Quote Post
jaca121212
post
Post #14





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Cytat(Turson @ 6.04.2015, 12:24:12 ) *
Czemu lepsze md5? Już dawno zostało złamane. Lepsza opcja to hash+sól

a mógłby mi ktoś pokzać przykład jak ma być to poprawinie zrobione lub jak to powinno wyglądać
Go to the top of the page
+Quote Post
Raito
post
Post #15





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


@jaca121212:
http://www.dobreprogramy.pl/Ardziej/Gdy-zw...malo,29553.html
@Turson:
Dzięki za info, nie wiedziałem o tym. Sam przy okazji sobie o tym poczytam (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
jaca121212
post
Post #16





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


mam problem z sprawdzaniem zmiennych czy istnieja w polach przy rejestracji np. czy haslo jest takie same jak haslo powtórzone w formularzu tak samo czy są wszystkie pola uzupełnione poprawilibyście ten skrypt
  1. <?php
  2.  
  3. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email'])))
  4. {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno!=0)
  12. {
  13. echo "Error: ".$polaczenie->connect_errno . "Opis: ". $polaczenie->connect_error;
  14. }
  15. else
  16. {
  17.  
  18. $login = $_POST['login'];
  19. $haslo = md5($_POST['haslo']);
  20. $haslo1 = md5($_POST['haslo1']);
  21. $email = $_POST['email'];
  22.  
  23. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  24. $haslo = htmlentities($haslo, ENT_QUOTES, "UTF-8");
  25. $haslo1 = htmlentities($haslo1, ENT_QUOTES, "UTF-8");
  26. $email = htmlentities($email, ENT_QUOTES, "UTF-8");
  27.  
  28. if(empty($_POST['login'])){
  29. echo "nie podałeś loginu";
  30.  
  31. }elseif(empty($_POST['haslo']==$_POST['haslo1'])){
  32. echo "hasła się różnią";
  33. }elseif(empty($_POST['email'])){
  34. echo "proszę podać adres e-mail";
  35. }else
  36.  
  37. if($resultat = $polaczenie->query(
  38. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s')",
  39. mysqli_real_escape_string($polaczenie, $login),
  40. mysqli_real_escape_string($polaczenie, $haslo),
  41. mysqli_real_escape_string($polaczenie, $email))))
  42. {
  43. $ilu_userow = $resultat->num_rows;
  44. if($ilu_userow>0)
  45. {
  46. $_SESSION['zarejestrowany'] = true;
  47.  
  48.  
  49.  
  50. unset($_SESSION['blad']);
  51. $resultat->free_result();
  52. header('Location: index.php');
  53. }else
  54. {
  55. $_SESSION['komunikat'] = '<span style="color:red" >Zostałeś/aś poprawnie zarejestrowany/na. Zaloguj się!</span>';
  56. header('Location: index.php');
  57. }
  58. }
  59. $polaczenie->close();
  60. }
  61.  
  62. ?>


  1. Rejestracja
  2. <form action="rejestracja.php" method="POST">
  3. Nazwa Użytkownika/login: <input type="text" name="login" /><br />
  4. Hasło: <input type="password" name="haslo" /><br />
  5. Powtórz hasło: <input type="password" name="haslo1" /><br />
  6. Adres E-mail: <input type="text" name="email" /> <br />
  7. <input type="submit" value="Zarejestruj się!!" name="wyślij" /><br />
  8. <?php
  9. if(isset($_SESSION['komunikat'])) echo $_SESSION['komunikat'];
  10. ?>

Go to the top of the page
+Quote Post
Raito
post
Post #17





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


  1. }elseif(empty($_POST['haslo']==$_POST['haslo1'])){
A coż to?
  1. elseif($_POST['haslo']!=$_POST['haslo1']){
  2. echo "Wpisane hasła różnią się.";}
  3. elseif(empty($_POST['haslo'])){
  4. ...
  5. }elseif(empty($_POST['haslo1'])){
  6. ...
  7. }


Ten post edytował Raito 6.04.2015, 19:40:04
Go to the top of the page
+Quote Post
Boshi
post
Post #18





Grupa: Zarejestrowani
Postów: 342
Pomógł: 15
Dołączył: 30.08.2011

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


Dla sprawdzenia czy wszystkie pola zostały uzupelnione wystarczy pętla foreach po tablicy POST

Ten post edytował Boshi 6.04.2015, 19:43:01
Go to the top of the page
+Quote Post
jaca121212
post
Post #19





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


W jaki sposób sprawdzić czy login taki jest w bazie jeśli tak to żeby pokazał komunikat

Ten post edytował jaca121212 7.04.2015, 06:49:33
Go to the top of the page
+Quote Post
Turson
post
Post #20





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Zapytaniem liczącym ilośc wierszy gdzie login = wpisany_login
Go to the top of the page
+Quote Post
jaca121212
post
Post #21





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Cytat(Turson @ 7.04.2015, 07:58:01 ) *
Zapytaniem liczącym ilośc wierszy gdzie login = wpisany_login

chodzi o takie coś
  1. $ilu_userow = $resultat->num_rows;
  2. if($ilu_userow>0)

Go to the top of the page
+Quote Post
Turson
post
Post #22





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Dokładnie
Go to the top of the page
+Quote Post
jaca121212
post
Post #23





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


to to mam zastosowane ale i tak dodoaje mi użytkownika o takim loginie może mam nie w tym miejscu dany

  1. $ilu_userow = $resultat->num_rows;
  2. if($ilu_userow>0)

sprawdziłbyś czy jest dobrze napisany skrypt pod kontem sprawdzania czy istnieje login a jeśli nie to byś mógł to poprawić
  1. <?php
  2.  
  3. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email'])))
  4. {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno!=0)
  12. {
  13. echo "Error: ".$polaczenie->connect_errno . "Opis: ". $polaczenie->connect_error;
  14. }
  15. else
  16. {
  17.  
  18. $login = $_POST['login'];
  19. $haslo = $_POST['haslo'];
  20. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  21. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  22. $hash = hash('sha512', $haslo . $sol . $sol2);
  23.  
  24. $haslo1 = $_POST['haslo1'];
  25. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  26. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  27. $hash = hash('sha512', $haslo . $sol . $sol2);
  28. $email = $_POST['email'];
  29.  
  30. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  31. $haslo = htmlentities($haslo, ENT_QUOTES, "UTF-8");
  32. $haslo1 = htmlentities($haslo1, ENT_QUOTES, "UTF-8");
  33. $email = htmlentities($email, ENT_QUOTES, "UTF-8");
  34.  
  35.  
  36.  
  37. if(empty($_POST['login'])){
  38. echo "nie podałeś loginu";
  39.  
  40. }elseif($_POST['haslo']!=$_POST['haslo1']){
  41. echo "Wpisane hasła różnią się.";}
  42. elseif(empty($_POST['haslo'])){
  43. echo"Nie wpisano hasła";
  44. }elseif(empty($_POST['haslo1'])){
  45. echo"Nie wpisano hasła";
  46.  
  47. }elseif(empty($_POST['email'])){
  48. echo "proszę podać adres e-mail";
  49. }else
  50.  
  51. if($resultat = $polaczenie->query(
  52. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s')",
  53. mysqli_real_escape_string($polaczenie, $login),
  54. mysqli_real_escape_string($polaczenie, $hash),
  55. mysqli_real_escape_string($polaczenie, $email))))
  56. {
  57. $ilu_userow = $resultat->num_rows;
  58. if($ilu_userow>0)
  59. {
  60. $_SESSION['zarejestrowany'] = true;
  61.  
  62.  
  63.  
  64. unset($_SESSION['blad']);
  65. $resultat->free_result();
  66. header('Location: index.php');
  67. }else
  68. {
  69. $_SESSION['komunikat'] = '<span style="color:red" >Zostałeś/aś poprawnie zarejestrowany/na. Zaloguj się!</span>';
  70. header('Location: index.php');
  71. }
  72. }
  73. $polaczenie->close();
  74. }
  75.  
  76. ?>
Go to the top of the page
+Quote Post
Turson
post
Post #24





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Źle to robisz, bo dodajesz użytkownika do bazy a dopiero potem sprawdzasz czy taki login już istnieje. Powinno być na odwrót
Go to the top of the page
+Quote Post
jaca121212
post
Post #25





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Jeśli dałem to w ten sposób to wyskoczył błąd
  1. <?php
  2.  
  3. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email'])))
  4. {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno!=0)
  12. {
  13. echo "Error: ".$polaczenie->connect_errno . "Opis: ". $polaczenie->connect_error;
  14. }
  15. else
  16. {
  17.  
  18. $login = $_POST['login'];
  19. $haslo = $_POST['haslo'];
  20. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  21. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  22. $hash = hash('sha512', $haslo . $sol . $sol2);
  23.  
  24. $haslo1 = $_POST['haslo1'];
  25. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  26. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  27. $hash = hash('sha512', $haslo . $sol . $sol2);
  28. $email = $_POST['email'];
  29.  
  30. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  31. $haslo = htmlentities($haslo, ENT_QUOTES, "UTF-8");
  32. $haslo1 = htmlentities($haslo1, ENT_QUOTES, "UTF-8");
  33. $email = htmlentities($email, ENT_QUOTES, "UTF-8");
  34.  
  35.  
  36.  
  37. if(empty($_POST['login'])){
  38. $ilu_userow = $resultat->num_rows;
  39. if($ilu_userow>0)
  40.  
  41. }elseif($_POST['haslo']!=$_POST['haslo1']){
  42. echo "Wpisane hasła różnią się.";}
  43. elseif(empty($_POST['haslo'])){
  44. echo"Nie wpisano hasła";
  45. }elseif(empty($_POST['haslo1'])){
  46. echo"Nie wpisano hasła";
  47.  
  48. }elseif(empty($_POST['email'])){
  49. echo "proszę podać adres e-mail";
  50. }else
  51.  
  52. if($resultat = $polaczenie->query(
  53. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s')",
  54. mysqli_real_escape_string($polaczenie, $login),
  55. mysqli_real_escape_string($polaczenie, $hash),
  56. mysqli_real_escape_string($polaczenie, $email))))
  57. {
  58.  
  59. {
  60. $_SESSION['zarejestrowany'] = true;
  61.  
  62.  
  63.  
  64. unset($_SESSION['blad']);
  65. $resultat->free_result();
  66. header('Location: index.php');
  67. }else
  68. {
  69. $_SESSION['komunikat'] = '<span style="color:red" >Zostałeś/aś poprawnie zarejestrowany/na. Zaloguj się!</span>';
  70. header('Location: index.php');
  71. }
  72. }
  73. $polaczenie->close();
  74. }
  75.  
  76. ?>


błąd jest taki
  1. Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\rejestracja.php on line 42
Go to the top of the page
+Quote Post
Turson
post
Post #26





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Wiem, że jest wcześnie, ale napij się kawy albo coś, bo nie myślisz logicznie kompletnie...

  1. if(empty($_POST['login'])){
  2. $ilu_userow = $resultat->num_rows;
  3. if($ilu_userow>0)

Jeżeli jest pusty login to "chcesz" sprawdzić czy taki login nie istnieje już, a na dodatek nawet nie masz ku temu zapytania i oczekujesz, że to $resultat->num_rows w jakiś magiczny sposób samo się zrobi. A, no i jeszcze otwierasz jeden warunek, innego nie zamykasz itp

Ten post edytował Turson 7.04.2015, 07:44:24
Go to the top of the page
+Quote Post
jaca121212
post
Post #27





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


poprawiłby ktoś ten kod bo już się w tym pogubiłem
  1. <?php
  2.  
  3. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email'])))
  4. {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno!=0)
  12. {
  13. echo "Error: ".$polaczenie->connect_errno . "Opis: ". $polaczenie->connect_error;
  14. }else
  15. {
  16.  
  17. $login = $_POST['login'];
  18. $haslo = $_POST['haslo'];
  19. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  20. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  21. $hash = hash('sha512', $haslo . $sol . $sol2);
  22.  
  23. $haslo1 = $_POST['haslo1'];
  24. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  25. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  26. $hash = hash('sha512', $haslo . $sol . $sol2);
  27. $email = $_POST['email'];
  28.  
  29. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  30. $haslo = htmlentities($haslo, ENT_QUOTES, "UTF-8");
  31. $haslo1 = htmlentities($haslo1, ENT_QUOTES, "UTF-8");
  32. $email = htmlentities($email, ENT_QUOTES, "UTF-8");
  33.  
  34. if($resultat = @$polaczenie->query(
  35. sprintf("SELECT * FROM uzytkownicy WHERE user= '%s' and pass='%s' and email='%s' ",
  36. mysqli_real_escape_string($polaczenie, $login),
  37. mysqli_real_escape_string($polaczenie, $hash),
  38. mysqli_real_escape_string($polaczenie, $email))))
  39. {
  40. $ilu_userow = $resultat->num_rows;
  41. if($ilu_userow>0)
  42. {
  43.  
  44. $resultat->free_result();
  45. header('Location: index.php');
  46. }
  47.  
  48.  
  49. if(isset($_POST['login'])){
  50. echo"Taki login już istnieje ";
  51. $_SESSION['blad2'] = '<span style="color:red" >Taki login już istnieje</span>';
  52. header('Location: index.php');
  53. }elseif($_POST['haslo']!=$_POST['haslo1']){
  54. echo "Wpisane hasła różnią się.";
  55. }elseif(empty($_POST['haslo']))
  56. {
  57. echo"Nie wpisano hasła";
  58. }elseif(empty($_POST['haslo1'])){
  59. echo"Nie wpisano hasła";
  60.  
  61. }elseif(empty($_POST['email'])){
  62. echo "proszę podać adres e-mail";
  63. }elseif($resultat = $polaczenie->query(
  64. sprintf("INSERT INTO `uzytkownicy` (`id`, `user`, `pass`, `email`) VALUES ('', '%s', '%s', '%s')",
  65. mysqli_real_escape_string($polaczenie, $login),
  66. mysqli_real_escape_string($polaczenie, $hash),
  67. mysqli_real_escape_string($polaczenie, $email))))
  68. {
  69.  
  70. $_SESSION['zarejestrowany'] = true;
  71.  
  72.  
  73.  
  74. unset($_SESSION['blad']);
  75. $resultat->free_result();
  76. header('Location: index.php');
  77. }else
  78. {
  79. $_SESSION['komunikat'] = '<span style="color:red" >Zostałeś/aś poprawnie zarejestrowany/na. Zaloguj się!</span>';
  80. header('Location: index.php');
  81. }
  82. }
  83. $polaczenie->close();
  84. }
  85.  
  86. ?>
Go to the top of the page
+Quote Post
Turson
post
Post #28





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Na szybko
  1. <?php
  2.  
  3.  
  4. if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])) || (!isset($_POST['haslo1'])) || (!isset($_POST['email']))) {
  5. header('Location: index.php');
  6. exit();
  7. }
  8.  
  9. require_once "polaczenie.php";
  10. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  11. if ($polaczenie->connect_errno != 0) {
  12. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  13. die();
  14. }
  15.  
  16. $login = trim($_POST['login']);
  17. $email = trim($_POST['email']);
  18. $haslo = trim($_POST['haslo']);
  19. $haslo1 = trim($_POST['haslo1']);
  20. $errors = array();
  21.  
  22. if (empty($login)) {
  23. $errors[] = 'Login jest pusty';
  24. }
  25.  
  26. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE user= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $login)));
  27. if ($resultat->num_rows == 1) {
  28. $errors[] = "Taki login już istnieje ";
  29. }
  30.  
  31. if (empty($haslo) || empty($haslo1)) {
  32. $errors[] = 'Wpisz hasła';
  33. }
  34.  
  35. if ($haslo != $haslo1) {
  36. $errors[] = "Wpisane hasła różnią się.";
  37. }
  38.  
  39. if (empty($_POST['email'])) {
  40. $errors[] = "proszę podać adres e-mail";
  41. }
  42.  
  43. if (count($errors) == 0) {
  44. // Brak błędów, to rejestrujemy
  45.  
  46. $sol = md5("192.168.0.1"); //sól użytkownika pobierana z bazy
  47. $sol2 = sha1("qOR8Dm1L"); //sól dodatkowa
  48. // Hasjujemy hasło
  49. $hash = hash('sha512', $haslo . $sol . $sol2);
  50.  
  51. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  52. $email = htmlentities($email, ENT_QUOTES, "UTF-8");
  53.  
  54. $resultat = $polaczenie->query(sprintf("INSERT INTO `uzytkownicy` (`user`, `pass`, `email`) VALUES (%s', '%s', '%s')", mysqli_real_escape_string($polaczenie, $login), mysqli_real_escape_string($polaczenie, $hash), mysqli_real_escape_string($polaczenie, $email)));
  55. $_SESSION['komunikat'] = '<span style="color:red" >Zostałeś/aś poprawnie zarejestrowany/na. Zaloguj się!</span>';
  56. $_SESSION['zarejestrowany'] = true;
  57. header('Location: index.php');
  58. } else {
  59. // Są błędy
  60. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  61. }
  62.  
  63. $polaczenie->close();
Go to the top of the page
+Quote Post
jaca121212
post
Post #29





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


dzięki działa tylko jest problem z przekierowanie na stronę index.php (IMG:http://www.iv.pl/images/87872295780514952373.png)
Go to the top of the page
+Quote Post
nospor
post
Post #30





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




A ty ten kod rejestracji masz w index.php ?
Go to the top of the page
+Quote Post
jaca121212
post
Post #31





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


nie w pliku rejestracja.php a formularz logowania i rejestracji jest w pliku index.php

Ten post edytował jaca121212 7.04.2015, 09:10:39
Go to the top of the page
+Quote Post
Raito
post
Post #32





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


A masz te pliki w tym samym miejscu?
Go to the top of the page
+Quote Post
jaca121212
post
Post #33





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


tak
Go to the top of the page
+Quote Post
Raito
post
Post #34





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Są w głównym katalogu localhost?
Go to the top of the page
+Quote Post
jaca121212
post
Post #35





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


Poradziłem sobie z tym kodem działa wszystko dzięki @Turson

teraz mam kolejny problem już nie chciałem zakładać nowego tematu więc napiszę tutaj
Proszę niech ktoś mi powie gdzie robię błąd w tym kodzie
  1. <?php
  2. if (!isset($_SESSION['zalogowany']))
  3. {
  4. header('Location: index.php');
  5. exit();
  6. }
  7. require_once "polaczenie.php";
  8. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  9. if ($polaczenie->connect_errno != 0) {
  10. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  11. die();
  12. }
  13. ?>
  14. <!DOCTYPE HTML>
  15. <html lang="pl">
  16. <head>
  17. <meta charset="utf-8"/>
  18. <title></title>
  19. </head>
  20. <body>
  21. Dodaj zdjęcie do profilu<br />
  22. <form action="" method="POST">
  23. <input type="url" name="image" /><br />
  24. <input type="submit" value="Dodaj zdjęcie"/><br />
  25. </form>
  26. <?php
  27. $image = trim($_POST['image']);
  28. $errors = array();
  29. if (empty($image)) {
  30. $errors[] = 'Nie dodano zdjęcia url. Przykład: <a href="http://localhost/phpmyadmin/themes/pmahomme/img/logo_left.png';" target="_blank">http://localhost/phpmyadmin/themes/pmahomm..._left.png';</a>
  31. }
  32.  
  33. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE image= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $image)));
  34. if ($resultat->num_rows == 1) {
  35. $errors[] = "Takie zdjęcie już istnieje ";
  36. }
  37. if (count($errors) == 0) {
  38.  
  39. $image = trim($_POST['image']);
  40.  
  41. $resultat = $polaczenie->query(sprintf('UPDATE `uzytkownicy` SET `id`= '$_SESSION['zalogowany']' and `image` = '%s' LIMIT 1',
  42.  
  43. mysqli_real_escape_string($polaczenie, $image)));
  44. echo"Dodano zdjęcie prawidłowo.";
  45. header('Location: gra.php');
  46. } else {
  47. // Są błędy
  48. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  49. }
  50.  
  51. ?>
  52. </body>
  53. </html>


chciałbym aby zalogowana osoba mogła dodać zdjęcie do swojego konta na teraz jest błąd taki
  1. Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE) in C:\xampp\htdocs\profil.php on line 42


Ten post edytował jaca121212 7.04.2015, 13:05:06
Go to the top of the page
+Quote Post
nospor
post
Post #36





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




nie: '$_SESSION['zalogowany']'
a: '.$_SESSION['zalogowany'].'

Podstawy operacji natekstach.. wypadałoby sie z nimi zapoznac.
Go to the top of the page
+Quote Post
Raito
post
Post #37





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Możesz zamienić apostrofy (na końcu i początku) na cudzysłowy.
Go to the top of the page
+Quote Post
jaca121212
post
Post #38





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


  1. błąd po dodaniu ..do zmiennej session jest taki
  2.  
  3. Parse error: syntax error, unexpected '' LIMIT 1'' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\profil.php on line 42

a jesli zmienilem na cudzyslowie to jest taki błąd
  1. Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\profil.php on line 42
Go to the top of the page
+Quote Post
Raito
post
Post #39





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Po zamianie na cudzysłowy daj tak: `id`= '".$_SESSION['zalogowany']."'
Go to the top of the page
+Quote Post
jaca121212
post
Post #40





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


nadal jest błąd
  1. Parse error: syntax error, unexpected '"' in C:\xampp\htdocs\profil.php on line 42

powiedz mi czy wgl jest dobrze napisane update

teraz wygłada to tak (IMG:http://www.iv.pl/images/17502248955983306599.png)

a kod php jest taki
  1. <?php
  2. if (!isset($_SESSION['zalogowany']))
  3. {
  4. header('Location: index.php');
  5. exit();
  6. }
  7. require_once "polaczenie.php";
  8. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  9. if ($polaczenie->connect_errno != 0) {
  10. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  11. die();
  12. }
  13. ?>
  14. <!DOCTYPE HTML>
  15. <html lang="pl">
  16. <head>
  17. <meta charset="utf-8"/>
  18. <title></title>
  19. </head>
  20. <body>
  21. Dodaj zdjęcie do profilu<br />
  22. <form action="" method="POST">
  23. <input type="url" name="image" /><br />
  24. <input type="submit" value="Dodaj zdjęcie"/><br />
  25. </form>
  26. <?php
  27. $image = trim($_POST['image']);
  28. $errors = array();
  29. if (empty($image)) {
  30. $errors[] = 'Nie dodano zdjęcia url. Przykład: <a href="http://localhost/phpmyadmin/themes/pmahomme/img/logo_left.png';" target="_blank">http://localhost/phpmyadmin/themes/pmahomm..._left.png';</a>
  31. }
  32.  
  33. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE image= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $image)));
  34. if ($resultat->num_rows == 1) {
  35. $errors[] = "Takie zdjęcie już istnieje ";
  36. }
  37. if (count($errors) == 0) {
  38.  
  39. $image = trim($_POST['image']);
  40.  
  41. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `id`= '".$_SESSION['zalogowany']."' and `image` = '%s'
  42. LIMIT 1",
  43.  
  44. mysqli_real_escape_string($polaczenie, $image)));
  45. echo"Dodano zdjęcie prawidłowo.";
  46. header('Location: gra.php');
  47. } else {
  48. // Są błędy
  49. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  50. }
  51.  
  52. ?>
  53. </body>
  54. </html>
Go to the top of the page
+Quote Post
Turson
post
Post #41





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Skrypt ma być wywołany tylko po przesłaniu obrazka, a nie nawet przed tym.
  1. if(!empty($POST['image'])){
  2. // tutaj kod od linii 28
  3. }


Poza tym update jest zły, bo masz zaktualizować tabelę i ustawić jakiś obrazek gdzie id uzytkownika jest jakieś, czyli
  1. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %d", $image, $_SESSION['zalogowany']));
Go to the top of the page
+Quote Post
jaca121212
post
Post #42





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


błędów nie ma ale nie dodaje obrazka do bazy kod teraz wygląda tak

  1. <?php
  2. if (!isset($_SESSION['zalogowany']))
  3. {
  4. header('Location: index.php');
  5. exit();
  6. }
  7. require_once "polaczenie.php";
  8. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  9. if ($polaczenie->connect_errno != 0) {
  10. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  11. die();
  12. }
  13. ?>
  14. <!DOCTYPE HTML>
  15. <html lang="pl">
  16. <head>
  17. <meta charset="utf-8"/>
  18. <title></title>
  19. </head>
  20. <body>
  21. Dodaj zdjęcie do profilu<br />
  22. <form action="" method="POST">
  23. <input type="url" name="image" /><br />
  24. <input type="submit" value="Dodaj zdjęcie"/><br />
  25. </form>
  26. <?php
  27. if(!empty($POST['image'])){
  28. $image = trim($_POST['image']);
  29. $errors = array();
  30. if (empty($image)) {
  31. $errors[] = 'Nie dodano zdjęcia url. Przykład: http://localhost/phpmyadmin/themes/pmahomm..._left.png';
  32. }
  33.  
  34. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE image= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $image)));
  35. if ($resultat->num_rows == 1) {
  36. $errors[] = "Takie zdjęcie już istnieje ";
  37. }
  38. if (count($errors) == 0) {
  39.  
  40. $image = trim($_POST['image']);
  41.  
  42. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %d", $image, $_SESSION['zalogowany']));
  43.  
  44. echo"Dodano zdjęcie prawidłowo.";
  45. header('Location: gra.php');
  46. } else {
  47. // Są błędy
  48. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  49. }
  50.  
  51. }
  52.  
  53. ?>
  54. </body>
  55. </html>

a jeśli dam tak to jest błąd
  1. <?php
  2. if (!isset($_SESSION['zalogowany']))
  3. {
  4. header('Location: index.php');
  5. exit();
  6. }
  7. require_once "polaczenie.php";
  8. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  9. if ($polaczenie->connect_errno != 0) {
  10. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  11. die();
  12. }
  13. ?>
  14. <!DOCTYPE HTML>
  15. <html lang="pl">
  16. <head>
  17. <meta charset="utf-8"/>
  18. <title></title>
  19. </head>
  20. <body>
  21. Dodaj zdjęcie do profilu<br />
  22. <form action="" method="POST">
  23. <input type="url" name="image" /><br />
  24. <input type="submit" value="Dodaj zdjęcie"/><br />
  25. </form>
  26. <?php
  27. if(!empty($POST['image'])){
  28. $image = trim($_POST['image']);
  29. $errors = array();
  30. if (empty($image)) {
  31. $errors[] = 'Nie dodano zdjęcia url. Przykład: <a href="http://localhost/phpmyadmin/themes/pmahomm..._left.png';" target="_blank">http://localhost/phpmyadmin/themes/pmahomm..._left.png';</a>
  32. }
  33.  
  34. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE image= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $image)));
  35. if ($resultat->num_rows == 1) {
  36. $errors[] = "Takie zdjęcie już istnieje ";
  37. }
  38. if (count($errors) == 0) {
  39.  
  40. $image = trim($_POST['image']);
  41.  
  42. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %d", $image, $_SESSION['zalogowany']));
  43.  
  44. mysqli_real_escape_string($polaczenie, $image)));
  45. echo"Dodano zdjęcie prawidłowo.";
  46. header('Location: gra.php');
  47. } else {
  48. // Są błędy
  49. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  50. }
  51. }
  52. ?>
  53. </body>
  54. </html>

  1. Parse error: syntax error, unexpected ')' in C:\xampp\htdocs\profil.php on line 45


Ten post edytował jaca121212 8.04.2015, 14:55:35
Go to the top of the page
+Quote Post
Raito
post
Post #43





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


1. Nie przepisuj bezmyślnie, bo chyba nie miało być $POST['image']?
2. Linia 43: nie powinien być przecinek zamiast średnika?

Ten post edytował Raito 8.04.2015, 14:58:18
Go to the top of the page
+Quote Post
jaca121212
post
Post #44





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


ok po zmianie działa tylko problem jest taki że zapisuje zdjęcie do pierwszego wolnego rekordu zamiast zapisywać do danego użytkownika który jest zalogowany niebieski kolor to osoba zalogowana czarny kolor to zapis do pierwszego rekordu w bazie (IMG:http://www.iv.pl/images/82398197952277188759.png) a kod wygląda tak
  1. <?php
  2. if (!isset($_SESSION['zalogowany']))
  3. {
  4. header('Location: index.php');
  5. exit();
  6. }
  7. require_once "polaczenie.php";
  8. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  9. if ($polaczenie->connect_errno != 0) {
  10. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  11. die();
  12. }
  13. ?>
  14. <!DOCTYPE HTML>
  15. <html lang="pl">
  16. <head>
  17. <meta charset="utf-8"/>
  18. <title></title>
  19. </head>
  20. <body>
  21. Dodaj zdjęcie do profilu<br />
  22. <form action="" method="POST">
  23. <input type="url" name="image" /><br />
  24. <input type="submit" value="Dodaj zdjęcie"/><br />
  25. </form>
  26. <?php
  27. if(!empty($_POST['image'])){
  28. $image = trim($_POST['image']);
  29. $errors = array();
  30. if (empty($image)) {
  31. $errors[] = 'Nie dodano zdjęcia url. Przykład: <a href="http://localhost/phpmyadmin/themes/pmahomm..._left.png';" target="_blank">http://localhost/phpmyadmin/themes/pmahomm..._left.png';</a>
  32. }
  33.  
  34. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE image= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $image)));
  35. if ($resultat->num_rows == 1) {
  36. $errors[] = "Takie zdjęcie już istnieje ";
  37. }
  38. if (count($errors) == 0) {
  39.  
  40. $image = trim($_POST['image']);
  41.  
  42. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %d", $image, $_SESSION['zalogowany']));
  43.  
  44. mysqli_real_escape_string($polaczenie, $image);
  45. echo"Dodano zdjęcie prawidłowo.";
  46. header('Location: gra.php');
  47. } else {
  48. // Są błędy
  49. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  50. }
  51. }
  52. ?>
  53. </body>
  54. </html>
Go to the top of the page
+Quote Post
Raito
post
Post #45





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Sprawdź, co zawiera $_SESSION['zalogowany'].

Ten post edytował Raito 8.04.2015, 15:13:55
Go to the top of the page
+Quote Post
jaca121212
post
Post #46





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


echo $_SESSION['zalogowany'];

zwraca 1
Go to the top of the page
+Quote Post
Raito
post
Post #47





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


A teraz sprawdź gdzie dodajesz to zdjęcie (zwróć szczególnie uwagę na klauzulę WHERE).
Go to the top of the page
+Quote Post
jaca121212
post
Post #48





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


  1. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %d",
  2. $image, $_SESSION['zalogowany']));


no ja myśle ze id= uzytkownik zalogowany nie mam pomysłu jak to zrobić żeby dobrze zapisywał

nawet jak dałem to w ten sposób to wyświetla mi tak
(IMG:http://www.iv.pl/images/77725600883763630631.png)


kod jest taki
  1. <?php
  2. if (!isset($_SESSION['zalogowany']))
  3. {
  4. header('Location: index.php');
  5. exit();
  6. }
  7. require_once "polaczenie.php";
  8. $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  9. if ($polaczenie->connect_errno != 0) {
  10. echo "Error: " . $polaczenie->connect_errno . "Opis: " . $polaczenie->connect_error;
  11. die();
  12. }
  13. ?>
  14. <!DOCTYPE HTML>
  15. <html lang="pl">
  16. <head>
  17. <meta charset="utf-8"/>
  18. <title></title>
  19. </head>
  20. <body>
  21. Dodaj zdjęcie do profilu<br />
  22. <form action="" method="POST">
  23. <input type="url" name="image" /><br />
  24. <input type="submit" value="Dodaj zdjęcie"/><br />
  25. </form>
  26. <?php
  27. if(!empty($_POST['image'])){
  28. $image = trim($_POST['image']);
  29. $errors = array();
  30. if (empty($image)) {
  31. $errors[] = 'Nie dodano zdjęcia url. Przykład: <a href="http://localhost/phpmyadmin/themes/pmahomm..._left.png';" target="_blank">http://localhost/phpmyadmin/themes/pmahomm..._left.png';</a>
  32. }
  33.  
  34. $resultat = $polaczenie->query(sprintf('SELECT `id` FROM uzytkownicy WHERE image= "%s" LIMIT 1', mysqli_real_escape_string($polaczenie, $image)));
  35. if ($resultat->num_rows == 1) {
  36. $errors[] = "Takie zdjęcie już istnieje ";
  37. }
  38. if (count($errors) == 0) {
  39.  
  40. $image = trim($_POST['image']);
  41. $login=($_SESSION['user'] == $_SESSION['zalogowany']);
  42. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %s",
  43. $image, $login));
  44.  
  45.  
  46. echo"Dodano zdjęcie prawidłowo.";
  47. header('Location: gra.php');
  48. } else {
  49. // Są błędy
  50. echo '<span style="color:red" >' . implode('<br>', $errors) . '</span>';
  51. }
  52. }
  53. echo $_SESSION['user'];
  54. echo"<br/>";
  55. echo $_SESSION['zalogowany'];
  56. ?>
  57. </body>
  58. </html>

to zapisuje do pierwszego wolnego rekordu w bazie czyli tak jak wyżej na obrazko
Go to the top of the page
+Quote Post
Raito
post
Post #49





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Albo dodajesz zdjęcie tam, gdzie user = $_SESSION["user"] (w tym przypadku każdy użytkownik musi mieć unikalną wartość user), albo zapisywać do sesji id użytkownika i zdjęcie dodać tam, gdzie id = $_SESSION["user_id"].
Go to the top of the page
+Quote Post
jaca121212
post
Post #50





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


jesli zapytanie update dałem w ten sposób to jest dalej to samo
  1. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %s",
  2. $image, $_SESSION['user'] ));


co
  1. $resultat = $polaczenie->query(sprintf("UPDATE `uzytkownicy` SET `image` = '%s' WHERE `id` = %d",
  2. $image, $_SESSION['zalogowany']));


jeśli możesz zrobić mi poprawne zapytanie to byłbym wdzięczny
Go to the top of the page
+Quote Post
Raito
post
Post #51





Grupa: Zarejestrowani
Postów: 156
Pomógł: 19
Dołączył: 27.04.2014

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


Czemu porównujesz id do usera? - WHERE user = $_SESSION["user"];
Go to the top of the page
+Quote Post
jaca121212
post
Post #52





Grupa: Zarejestrowani
Postów: 256
Pomógł: 16
Dołączył: 21.12.2014

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


po zmianie zapisuje mi wszędzie w polu image obrazek przeslany (IMG:http://www.iv.pl/images/46967309900856836766.png) dlatego musi byc id usera zalogowanego
Go to the top of the page
+Quote Post

3 Stron V   1 2 3 >
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: 26.09.2025 - 08:02