Guest User

Untitled

a guest
Dec 9th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. class Prisijungimas {
  4.  
  5. var $host;
  6. var $username;
  7. var $password;
  8. var $db;
  9.  
  10. function connect(){
  11.  
  12. $con = mysql_connect($this->host, $this->username, $this->password)or die (mysql_error());
  13. mysql_select_db($this->db, $con)or die (mysql_error());
  14.  
  15. }
  16.  
  17. function Gavimas(){
  18.  
  19. $sql = "SELECT * FROM tvs_content";
  20. $res = mysql_query($sql)or die (mysql_error());
  21. while($row = mysql_fetch_assoc($res)){
  22. echo '<h1>' . $row['title'] . '</h1>';
  23. echo '<p>' . $row['body'] . '</p>';
  24. }
  25.  
  26. }
  27.  
  28. function Prideti($p){
  29.  
  30. $title = mysql_real_escape_string($p['title']);
  31. $body = mysql_real_escape_string($p['body']);
  32.  
  33. if(!$title || $body):
  34.  
  35. if(!$title):
  36. echo "<p>Ne&#303;vestas pavadinimas!</p>";
  37. endif;
  38. if(!$body):
  39. echo "<p>Ne&#303;vestas textas!</p>";
  40. endif;
  41.  
  42. echo "<a href='newnaujiena.php'><p>Pakartoti i&#353; naujo!</p></a>";
  43.  
  44. else:
  45. $sql = "INSERT INTO tvs_content VALUES (null, '$title', '$body'";
  46. $res = mysql_query($sql)or die (mysql_error());
  47. echo "<p>Naujiena Prideta!</p>";
  48. endif;
  49. }
  50.  
  51. } //Pabaiga
  52.  
  53. $obj = new Prisijungimas();
  54. $obj->host = 'localhost';
  55. $obj->username = 'root';
  56. $obj->password = '';
  57. $obj->db = 'lvlifetvs';
  58. $obj->connect();
  59.  
  60. ?>
Add Comment
Please, Sign In to add comment