Advertisement
modInfo

Untitled

Oct 26th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. // jedna mała funkcja
  2. function cleanText($wert) {
  3. $wert = strip_tags($wert);
  4. $wert = htmlentities($wert, ENT_QUOTES, "UTF-8");
  5. $wert = trim($wert);
  6. $wert = stripslashes($wert);
  7. $wert = nl2br($wert);
  8. //$wert = mysql_real_escape_string($wert); // Jeżeli używasz PDO to zakomentuj to, jeżeli mysql_query to odkoduj
  9.  
  10. return $wert;
  11. }
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. // przykład użycia
  19.  
  20. $text  = cleanText($_POST['text']);
  21. $time  = cleanText(  time()  );
  22. $id    = cleanText($_GET['id']);
  23.  
  24. //dodawanie do mysql
  25. $db->query("INSERT INTO `user` (`id_user`, `punkty`) VALUES ('$text', '$time');");
  26.  
  27.  
  28.  
  29. //wyświetlanie z mysql
  30. $sql = $db->query("SELECT * FROM user WHERE id='$id' ");
  31. foreach($sql as $row) {
  32.    echo $row['text'];
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement