title: $_GET variable is query not working when passed
body: <p>Im using the following to assign a value to a variable if the variable is passed via the URL:</p>
  
  <pre><code>if (!empty($_POST)) {
      $sortBy = isset($_GET['sort']) ? $_GET['sort'] : 'mgap_ska_id';
  }
  </code></pre>
  
  <p>here is where the variable is being passed:</p>
  
  <pre><code>$result = "SELECT mgap_ska_id, mgap_ska_id_name, SUM(DISTINCT mgap_growth) as growthtotal, SUM(DISTINCT mgap_recovery) as recovery FROM mgap_orders "
          . "WHERE account_manager_id = '" . $_SESSION['account_manager_id'] . "' GROUP BY mgap_ska_id ORDER BY '".$sortBy. "' ";
  </code></pre>
  
  <p>The process is working fine if the variable isnt being passed, but the variable in the query becomes unassigned when passed through the link like such:</p>
  
  <pre><code>&lt;a href = "customer_view.php?sort=mgap_ska_id_name"&gt;
  </code></pre>
  
  <p>Can anyone see where my error is?</p>
  
  <p>FYI Ive tried it in the query with and without the quotes.</p>
  
  <p><strong>EDIT WITH SOLUTION:</strong></p>
  
  <p>Here is how I solved the problem: O checked for both POST and GET:</p>
  
  <pre><code> if (!empty($_GET) || !empty($_POST)) {
      $sortBy = isset($_GET['sort']) ? $_GET['sort'] : 'mgap_ska_id';
  }  else {
  $sortBy = 'mgap_ska_id';    
  }
  </code></pre>