title: Input from user not displaying on server side page properly after running query
body: <p>Currently I have a form where the user picks a movie and it's value is the movieID</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form method="GET" action="http://localhost:8080"&gt;
    &lt;div id="radio-section"&gt;
      &lt;input type="radio" id="wake" name="movie" value="954"&gt;
      &lt;label for="wake"&gt;Wake Jaws&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="radio" id="tomato" name="movie" value="894"&gt;
      &lt;label for="tomato"&gt;Tomato Hellfighters&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="radio" id="west" name="movie" value="969"&gt;
      &lt;label for="west"&gt;West Lion&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="radio" id="edge" name="movie" value="272"&gt;
      &lt;label for="edge"&gt;Edge Kissing&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="radio" id="lolita" name="movie" value="528"&gt;
      &lt;label for="lolita"&gt;Lolita World&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="radio" id="dancing" name="movie" value="206"&gt;
      &lt;label for="dancing"&gt;Dancing Fever&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="radio" id="random" name="movie" value="random"&gt;
      &lt;label for="random"&gt;Show me a random movie!&lt;/label&gt;
      &lt;br&gt;
    &lt;/div&gt;
    &lt;input type="submit"&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>The input gets pulled and then used within a query string that pulls the movie based of the ID user input and then displays back the movie title and description through node.js</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let http = require("http");
  let mysql = require("mysql");
  const PORT = 8080;
  let output = '';
  let con;
  let count = 0;
  
  initializeDB();
  let httpServer = http.createServer(processServerRequest);
  
  httpServer.listen(PORT);
  
  function processServerRequest(request, response){
  
      grabInput(request);
  
      console.log(`${output} recieved`);
      response.writeHead(200, {'Content-Type':'text/html'});
      response.write('Here is the information you were looking for');
      response.write(output);
      response.end();
  } //end of processServerRequest fucntion 
  
  function grabInput(request){
      let base = "http://" + request.headers["host"];
      let url = new URL(request.url, base);
  
      console.log('Grabbing results...');
  
      let movieID = url.searchParams.get("movie");
      
      if (movieID == 'random'){
          movieID = Math.floor(Math.random() * 1000) + 1;
      }
  
      let sqlquery = `select title, description from film where film_id = ${movieID};`
      con.query(sqlquery, processResult);
  }
  
  function processResult(err, result){
      if (err){
          console.log("Error detected.");
          throw err;
      } //end of if statement
      else{
          console.log(`page opened ${count} times`)
          count++;
          console.log(`There were ${result.length} rows returned`);
          result.forEach(printMovie);
      } // end of else statement
  } //end of processResult function 
  
  function printMovie(record){
      console.log(`${record.title} ${record.description}`);
      output=`&lt;p&gt;&lt;strong&gt;${record.title}&lt;/strong&gt;&lt;br&gt;&lt;br&gt;${record.description}&lt;/p&gt;`;
  }</code></pre>
  </div>
  </div>
  </p>
  <p>For some reason, instead of just displaying the correct output, it initially does not have the movie title and description after I press submit. When I go back to the form page and select another movie and press select again, it then displays the movie information for the one I selected before.</p>
  <p>example:</p>
  <ol>
  <li>I select Jaws and press submit</li>
  <li>nothing displays</li>
  <li>I go back select Spiderman and press submit</li>
  <li>Jaw movie information displays</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/EoFh9.jpg" rel="nofollow noreferrer">node.js output</a></p>
  <p>It looks like my processResult function runs twice, grabbing the correct output the first time, but then running again and assigning output to an empty string. How can I make it so it displays the proper movie information?</p>