Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2. /*
  3.     @file news.class.php
  4.     @author ErF
  5.     @date 04.05.2010r.
  6.     @copyright 2010r.
  7. */
  8.  
  9.     class News
  10.     {
  11.         private $host = "";
  12.         private $user = "";
  13.         private $pass = "";
  14.         private $db_name = "";
  15.         private $limit = 0;
  16.         private $con = 0;
  17.        
  18.         public function __construct()
  19.         {
  20.             require("config.php");
  21.             $this->host = $host;
  22.             $this->user = $user;
  23.             $this->pass = $password;
  24.             $this->db_name = $db_name;
  25.            
  26.             $this->con = @mysql_connect($this->host, $this->user, $this->password) or die ("Unable to connect database.");
  27.             @mysql_select_db($this->db_name) or die ("Unable to select database.");
  28.         }
  29.         public function addNews($author, $title, $body, $cat)
  30.         {
  31.             $author = $this->usun($author);
  32.             $title = $this->usun($title);
  33.             $body = $this->usun($body);
  34.             $cat = $this->usun($cat);
  35.            
  36.             $query = sprintf("INSERT INTO `news` (`title`, `body`, `author`, `cat`, `date`) VALUES ('%s', '%s', '%s', '%d', CURDATE())", $title, $body, $author, $cat);
  37.             $res = @mysql_query($query);
  38.            
  39.         }
  40.         public function delNews($id)
  41.         {
  42.             $id = $this->usun($id);
  43.            
  44.            
  45.             if(is_numeric($id))
  46.             {
  47.                 @mysql_query("DELETE FROM `news` WHERE id = '$id'");
  48.                 $this->closeMySQL($this->con);
  49.             }
  50.         }
  51.         public function editNews($id, $title, $body, $cat)
  52.         {
  53.             $id = $this->usun($id);
  54.             $title = $this->usun($title);
  55.             $body = $this->usun($body);
  56.             $cat = $this->usun($cat);
  57.            
  58.            
  59.             if(is_numeric($id))
  60.             {
  61.                 $query = sprintf("UPDATE `news` SET title = '%s', body = '%s' AND cat = '%d' WHERE `id` = '%d'", $title, $body, $cat, $id);
  62.                 $res = @mysql_query($query);
  63.                 $this->closeMySQL($this->con);
  64.             }
  65.         }
  66.         private function closeMySQL()
  67.         {
  68.             mysql_close($this->con);
  69.         }
  70.         public function usun($val)
  71.         {
  72.             if(get_magic_quotes_gpc())
  73.             {
  74.                 $val = stripslashes($val);
  75.             }
  76.             $val = mysql_real_escape_string($val);
  77.            
  78.             return $val;
  79.         }
  80.     }
  81.  
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement