Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Zmienna $_GET
JulekJP
post
Post #1





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 7.03.2009

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


Witam, mam dość skomplikowany problem dla mnie i nie wiem jak go wyrazić.. Po prostu chce zrobić zmienna GET gdzie w adresie np dodam ?krok=edytuj&id=[id_usera] to mi wyświetli dane z bazy danych tylko o id usera podanym w adresie(get). Prosił bym o pomoc. Poniżej podaje skrypt pliku..

  1. <?php
  2. require("../manicore.php");
  3. require("../header.php");
  4. if (!$datauser['user_level'] == 103)
  5. { header("Location: ../login.php"); exit; } else {
  6. $krok = $_GET['krok'];
  7. $result = mysql_query("SELECT * FROM user ORDER BY user_name");
  8. $data = mysql_fetch_assoc($result);
  9.  
  10. echo "<div id=\"conten\">
  11. <div id=\"conten_01\">";
  12. if ($krok == "edytuj&amp;id=".$data['id'])
  13. {
  14. echo " czesc";
  15. }
  16. if (!$krok)
  17. {
  18. ?>
  19. <table width="70%" border="0">
  20. <tr>
  21. <td><strong>Nazwa klienta</strong></td>
  22. <td align="center"><strong>Typ</strong></td>
  23. <td><strong>Opcje</strong></td>
  24. </tr>
  25. <?php
  26. for($i = 0; $i < mysql_num_rows($result); $i++)
  27. {
  28. $data = mysql_fetch_assoc($result);
  29. echo "<tr>
  30. <td>".$data['user_names']." ".$data['user_name']."</td>
  31. <td>".getuserlevel($data['user_level'])."</td>
  32. <td>[edytuj] | [usuń]</td>
  33. </tr>";
  34. }
  35.  
  36. }
  37. echo "</table>";
  38. echo "<br class=\"clearfloat\" />";
  39. echo "</div>";
  40. }
  41. require("../footer.php");
  42. ?>


Jak widać zrobiłem to tak.. ;|
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
MateuszS
post
Post #2





Grupa: Zarejestrowani
Postów: 1 429
Pomógł: 195
Dołączył: 6.10.2008
Skąd: Kraków/Tomaszów Lubelski

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


  1.  
  2. if(isset($_GET["edytuj"]))
  3. {
  4. if(isset($_GET["id_usera"])) {
  5. //tu ten kod edycji,
  6. }
  7. }
  8.  


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





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 7.03.2009

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


Zrobiłem tak

  1. if($_GET['edycja'])
  2. {
  3. echo "problem";
  4. $result = mysql_query("SELECT * FROM user WHERE id=".$_GET['edycja']." ");
  5. $user = mysql_fetch_assoc($result);
  6. echo $user['user_name'];
  7. }


i w adresie wpisując ?edycja=2 nie wyświetla mi danych a jak dam swoje id czyli 1 to wyświetla mi dane ;|
Go to the top of the page
+Quote Post
luck
post
Post #4





Grupa: Zarejestrowani
Postów: 317
Pomógł: 58
Dołączył: 6.11.2005

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


Na pewno masz w bazie usera o id=2? Co się dzieje jeśli na sztywno podasz takie id w zapytaniu? Jaki jest wynik?
BTW. W wolnym czasie poczytaj o SQL Injection. Serio, poczytaj.


--------------------
Go to the top of the page
+Quote Post
JulekJP
post
Post #5





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 7.03.2009

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


A no sorry nie ma id 2 moja wina.. dlaczego mam poczytać o SQL Injection? Coś słyszałem o tym
Go to the top of the page
+Quote Post
luck
post
Post #6





Grupa: Zarejestrowani
Postów: 317
Pomógł: 58
Dołączył: 6.11.2005

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


Choćby dlatego, że pozwolenie na wysłanie do bazy takiego zapytania:
  1. mysql_query("SELECT * FROM user WHERE id=".$_GET['edycja']." ")
to programistyczne samobójstwo. To są bardzo poważne rzeczy, dlatego zwracam Ci na nie uwagę.


--------------------
Go to the top of the page
+Quote Post
JulekJP
post
Post #7





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 7.03.2009

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


No jedna osoba mi pisała.. Przeczytałem sobie o SQL Injection i wiem jak wykorzystać to ale jak zabezpieczyć się przed tym to nadal nie wiem.. Morzę masz jakąś strone gdzie dowiem sie jak zabespieczyć? Albo ty morze mi pomożesz?
Go to the top of the page
+Quote Post
luck
post
Post #8





Grupa: Zarejestrowani
Postów: 317
Pomógł: 58
Dołączył: 6.11.2005

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


Polecam ten wątek: Temat: SQL Injection Insertion
A na początek możesz dać choćby
  1. "SELECT * FROM user WHERE id=".mysql_real_escape_string($_GET['edycja'])


--------------------
Go to the top of the page
+Quote Post
JulekJP
post
Post #9





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 7.03.2009

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


Cały kod pliku wygląda tak.. Czy jest dobrze?

  1. <?php
  2. require("../manicore.php");
  3. require("../header.php");
  4. if (!$datauser['user_level'] == 103)
  5. { header("Location: ../login.php"); exit; } else {
  6.  
  7. echo "<div id=\"conten\">
  8. <div id=\"conten_01\">";
  9.  
  10.  
  11. if($_GET['edycja'])
  12. {
  13. $edycja = mysql_real_escape_string($_GET['edycja']);
  14. $result = mysql_query("SELECT * FROM user WHERE id=$edycja ");
  15. $user = mysql_fetch_assoc($result);
  16. echo $user['user_name'];
  17. } else {
  18. ?>
  19. <table width="70%" border="0">
  20. <tr>
  21. <td><strong>Nazwa klienta</strong></td>
  22. <td align="center"><strong>Typ</strong></td>
  23. <td><strong>Opcje</strong></td>
  24. </tr>
  25. <?php
  26. $result = mysql_query("SELECT * FROM user ORDER BY user_name");
  27. for($i = 0; $i < mysql_num_rows($result); $i++)
  28. {
  29. $data = mysql_fetch_assoc($result);
  30. echo "<tr>
  31. <td>".$data['user_names']." ".$data['user_name']."</td>
  32. <td>".getuserlevel($data['user_level'])."</td>
  33. <td>[edytuj] | [usun]</td>
  34. </tr>";
  35. }
  36.  
  37. }
  38. echo "</table>";
  39. echo "<br class=\"clearfloat\" />";
  40. echo "</div>";
  41. }
  42. require("../footer.php");
  43. ?>


Ten post edytował JulekJP 11.03.2010, 20:45:35
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 Aktualny czas: 19.08.2025 - 07:27