SHARE
TWEET

Untitled

a guest Jan 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4.  
  5. // Av Matilda Wiklund, 2018-08-20
  6.  
  7.  
  8. class moviePosts {
  9.    
  10. private $db;
  11. private $ID;
  12. private $username;
  13. private $movie;
  14. private $genre;
  15.  
  16.         // Constructor
  17.         function __construct() {
  18.             // Connect to database
  19.             $this->db = new mysqli(DBHOST, DBUSER, DBPASS, DBDATABASE);
  20.             if($this->db->connect_errno > 0) {
  21.                 die("Fel vid anslutning: " . $this->db->connect_error);
  22.             }
  23.         }
  24.  
  25.         // Register new post
  26.         public function registermoviePosts( $movie, $genre) {
  27.             $title = $this->db->real_escape_string($movie);
  28.             $post = $this->db->real_escape_string($genre);
  29.  
  30.             $sql = "INSERT INTO movies(userID, movie, genre) VALUES ((SELECT userID FROM users WHERE username = '{$_SESSION['username']}'), '$movie', '$genre')";
  31.              return $result = $this->db->query($sql);
  32.            
  33.          
  34.  
  35.  
  36.             $result = $this->db->query($sql);  
  37.            
  38.             return $result;
  39.         }
  40.  
  41.         // Get post
  42.  
  43.         public function getmoviePosts( $num = "", $username = ""){
  44.             $where = "";
  45.             $limit = "";
  46.             if (!empty($username)) {
  47.                 $where = "WHERE movies.userID = (SELECT user.userID FROM users WHERE username = '$username') ";
  48.             }
  49.  
  50.             if (!empty($num)) {
  51.                 $limit = "LIMIT $num";
  52.             }
  53.  
  54.            $sql = <<<__ENDIF
  55.         SELECT moviepost.*, users.username FROM moviepost
  56.             LEFT JOIN users
  57.             ON users.userID = moviepost.userID
  58.             $where
  59.             ORDER BY moviepost.created DESC
  60.             $limit;
  61. __ENDIF;
  62.             $result = $this->db->query($sql);
  63.            
  64.             $array = array();
  65.  while($row = $result->fetch_assoc())
  66.    $array[] = $row;
  67.  return $array;
  68.         }
  69.  
  70.  
  71.         public function getmoviePostsFromId($ID){
  72.             $ID=intval($ID);
  73.             $sql = "SELECT * FROM moviepost WHERE id=$ID";
  74.  
  75.             $result = $this->db->query($sql);
  76.             $row = mysqli_fetch_array($result);
  77.  
  78.             return $row;
  79.         }        
  80.        
  81.        
  82.       //  Update post
  83.       public function updatemoviePosts( $movie, $genre, $ID) {
  84.         $ID = intval($ID);
  85.      
  86.         $sql = "UPDATE moviepost SET title='" . $movie . "',  post=' " . $genre . " ' WHERE id=$ID";
  87.            
  88.             return $result = $this->db->query($sql);
  89.         }
  90.          
  91.  
  92.         // Delete post
  93.  
  94.         public function deletemoviePosts($ID){
  95.             $id = intval($id);
  96.             $sql =  "DELETE  FROM moviepost WHERE id=$ID";
  97.             $this->db->query($sql);
  98.         }
  99.  
  100.  
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top