public function newUser($username, $password, $email) { $insertResult = DB::insert('users', ['username' => $username, 'password' => password_hash($password, PASSWORD_DEFAULT), 'email' => $email], self::USER_TYPES); $queryResult['success'] = is_bool($insertResult) ? true : false; $queryResult['error'] = is_string($insertResult) ? $insertResult : ''; return $queryResult; }
public function getMoviesID() { //connect to database : include '../autoloader.php'; $db2 = DB::getDB(); //Execute the Query $queryAllMoviesId = 'SELECT film_id FROM moviefeature'; $getId = $db2->prepare($queryAllMoviesId); $getId->execute(); $getIds = $getId->fetchAll(); $getId->closeCursor(); return $getIds; }
public function saveMenu(array $menus) { // truncate, very bad DB::getDB()->exec('TRUNCATE menus'); $stmt = DB::getDB()->prepare('INSERT INTO menus VALUES (:name, :menu) ON DUPLICATE KEY UPDATE name = :name, menu = :menu'); foreach ($menus as $menu) { $stmt->bindParam(':name', $menu['name'], \PDO::PARAM_STR); $stmt->bindParam(':menu', json_encode($menu['menu']), \PDO::PARAM_STR); if (!$stmt->execute()) { return false; } } return true; }
private function updateCookie($userId) { $id = hash('sha256', mt_rand()); $token = password_hash(mt_rand(), PASSWORD_DEFAULT); $rememberStmt = $this->db->prepare(' INSERT INTO tokens (id, token, user_id) VALUES(:id, :token, :user_id) ON DUPLICATE KEY UPDATE token = :token; '); $rememberStmt = DB::bindValues($rememberStmt, ['id' => $id, 'user_id' => $userId, 'token' => $token], self::TOKEN_TYPES); if ($rememberStmt->execute()) { $cookie = "{$id};{$token}"; return setcookie('rememberme', $cookie, time() + 604800, '/', '', false, true); } else { return false; } }
<?php use Project\Classes\DB\DB; include '../../autoloader.php'; require_once '../Model/Filmadmin.php'; //require_once '../../FilmAdmin_CMS/Model/Filmadmin.php'; require_once 'manage_movie.php'; $db = DB::getDB(); //validate date $date_regex = '/^(19|20)\\d\\d[\\-\\/.](0[1-9]|1[012])[\\-\\/.](0[1-9]|[12][0-9]|3[01])$/'; // Validate inputs if (empty($title) || empty($releaseDate) || empty($cast) || empty($director) || empty($thumbnail)) { echo "<span style='color:red;font-size:24px;'>"; $error = "Invalid Movie data. Check all fields and try again."; echo $error; echo "</span>"; } else { if (!preg_match($date_regex, $releaseDate)) { $error = "Your date entry does not match the YYYY-MM-DD required format."; echo "<span style='color:red;font-size:24px;'>"; echo $error; echo "</span>"; } else { // If valid, update the movie to the database $thumbnail = "/Assets/image/HomePage/" . "thumb_" . $file_get; $updatingMovie = new Filmadmin(); $updatingMovie->updateMovie($title, $releaseDate, $director, $cast, $thumbnail, $film_id); // Display the Movie List page // header('location: ../View/IndexMovies_AdminView.php'); header('location: /admin/movie'); }
public function __construct() { $this->db = DB::getDB(); Helper::startSession(); }
<?php use Project\Classes\DB\DB; require_once './Model/Ratings.php'; require_once '../autoloader.php'; require_once 'database.php'; require_once '../FilmAdmin_CMS/Model/Filmadmin.php'; $db = Database::getDB(); $db2 = DB::getDB(); $getMovieID = new Filmadmin(); $getMoviesId = $getMovieID->getMoviesID(); //define quantity of movies in array and it's display rating system for that $ids = array(); foreach ($getMoviesId as $film) { // $ids = $film['film_id']; array_push($ids, $film['film_id']); $filename_arr = $ids; $Movieid = implode(',', $filename_arr); } ?> <html> <head> <meta charset="UTF-8"> <title>Rate Movie</title> <script src="jquery.js" type="text/javascript"></script> <link rel="stylesheet" href="rating.css" /> <script type="text/javascript" src="rating.js"></script> </head> <body>
public function delete($id) { $stmt = DB::getDB()->prepare('DELETE FROM pages WHERE id = :id'); self::bindValues($stmt, [':id' => $id]); return $stmt->execute() == 1 ? true : false; }
public function contactProcess() { //connect to database : include '../../../autoloader.php'; $db = DB::getDB(); $first_name = htmlspecialchars($_POST['first_name']); $last_name = htmlspecialchars($_POST['last_name']); $Email = htmlspecialchars($_POST['Email']); $Message = htmlspecialchars($_POST['Message']); // Now inserting form values to the database table $query = "INSERT INTO contactus(first_name,last_name,Email,Message) VALUES ('{$first_name}','{$last_name}','{$Email}','{$Message}')"; $contactQuery = $db->prepare($query); $contactQuery->execute(); $contactQuery->closeCursor(); }