Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Av Matilda Wiklund, 2018-08-20
- class moviePosts {
- private $db;
- private $ID;
- private $username;
- private $movie;
- private $genre;
- // Constructor
- function __construct() {
- // Connect to database
- $this->db = new mysqli(DBHOST, DBUSER, DBPASS, DBDATABASE);
- if($this->db->connect_errno > 0) {
- die("Fel vid anslutning: " . $this->db->connect_error);
- }
- }
- // Register new post
- public function registermoviePosts( $movie, $genre) {
- $title = $this->db->real_escape_string($movie);
- $post = $this->db->real_escape_string($genre);
- $sql = "INSERT INTO movies(userID, movie, genre) VALUES ((SELECT userID FROM users WHERE username = '{$_SESSION['username']}'), '$movie', '$genre')";
- return $result = $this->db->query($sql);
- $result = $this->db->query($sql);
- return $result;
- }
- // Get post
- public function getmoviePosts( $num = "", $username = ""){
- $where = "";
- $limit = "";
- if (!empty($username)) {
- $where = "WHERE movies.userID = (SELECT user.userID FROM users WHERE username = '$username') ";
- }
- if (!empty($num)) {
- $limit = "LIMIT $num";
- }
- $sql = <<<__ENDIF
- SELECT moviepost.*, users.username FROM moviepost
- LEFT JOIN users
- ON users.userID = moviepost.userID
- $where
- ORDER BY moviepost.created DESC
- $limit;
- __ENDIF;
- $result = $this->db->query($sql);
- $array = array();
- while($row = $result->fetch_assoc())
- $array[] = $row;
- return $array;
- }
- public function getmoviePostsFromId($ID){
- $ID=intval($ID);
- $sql = "SELECT * FROM moviepost WHERE id=$ID";
- $result = $this->db->query($sql);
- $row = mysqli_fetch_array($result);
- return $row;
- }
- // Update post
- public function updatemoviePosts( $movie, $genre, $ID) {
- $ID = intval($ID);
- $sql = "UPDATE moviepost SET title='" . $movie . "', post=' " . $genre . " ' WHERE id=$ID";
- return $result = $this->db->query($sql);
- }
- // Delete post
- public function deletemoviePosts($ID){
- $id = intval($id);
- $sql = "DELETE FROM moviepost WHERE id=$ID";
- $this->db->query($sql);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement