title: mysqli_query will not execute
body: <p>I am currently trying to get an <code>mysqli_query</code> to execute, however when I run it I am told that the query has failed. I am not sure what the problem is, because my php file is connecting to the database server. Below is my code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
  &lt;link rel="icon" href="../img/favicon.ico"&gt;
  &lt;link href="css/custom.css" rel="stylesheet" type="text/css" /&gt;
  
  &lt;title&gt;Assignment 8: Building a "LAMP" Website for your MySQL Data&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="container"&gt;
      &lt;header&gt;
          &lt;h1&gt;&lt;mark&gt;"LAMP" Website for MYSQL Movie Databse&lt;mark&gt;&lt;/h1&gt;
      &lt;/header&gt;
  
      &lt;section&gt;
      &lt;p&gt;Please include the following notes on your page along with an introduction to the data for your user: 1. The source for your data. Is this meant to be a user-based system? or will the data come from downloads? Are the current data test data only? 2. Write at least one paragraph to describe your project. 3. Write at least one paragraph to describe your project. You might wish to refer to our class discussion on specifications for ideas.&lt;/p&gt;
  
          &lt;?php
              /* Connecting and selecting database */
              include ('/home/as7695/db_files/db_config.php');
  
              $db_link = new mysqli($db_server, $db_user, $db_password, $db_name);
              if ($db_link-&gt;connect_errno) {
              print( "Failed to connect to MySQL: (" .$db_link-&gt;connect_errno . ") ".$db_link-&gt;connect_error);
              }
              print("&lt;p&gt;Connection: ".$db_link-&gt;host_info . "&lt;br /&gt;\n");
              print( nl2br("Connected successfully\n"));
  
              /* Setting variables */
              $nationality = $_POST['nationality'];
              $genre = $_POST['genre'];
              $limit = $_POST['limit'];
              $sortkey = $_POST ['sortkey'];
  
              /* Performing SQL query using criteria supplied by the user on the HTML form */
              $query = "SELECT CONCAT (movies.title, ' (', movies.release_year, ')') AS Title, CONCAT (movies.rating) AS Rating, CONCAT (directors.first_name, ' ', directors.last_name) AS Director, GROUP CONCAT (actors.first_name, ' ', actors.last_name separator ', ') AS Actors, CONCAT (movies.description) AS Description
              FROM movies
              INNER JOIN directors ON movies.directorID = directors.directorID
              INNER JOIN movie_actors ON movies.movieID = movie_actors.movieID
              INNER JOIN actors ON movie_actors.actorID = actors.actorID
              INNER JOIN movie_genres ON movies.movieID = movie_genres.movieID
              INNER JOIN genres ON movie_genres.genreID = genres.genreID
              WHERE directors.nationality = '$nationality' AND genres.genre_name = '$genre'
              GROUP BY movies.movieID
              ORDER BY movies.release_year '$sortkey'
              LIMIT '$limit'";
  
              /* Store result as a variable and see how many records are returned */
              $result = mysqli_query($db_link,$query) or die("Query failed : " . mysqli_error());
  
              /* Closing connection */
              mysqli_close($db_link);
          ?&gt;
      &lt;/section&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>