title: MYSQL supplied argument is not a valid MySQL-Link resource
body: <p>ERROR:</p>
  
  <pre><code>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/247QC/system/core.php on line 21
  Invalid query: Whole query: SELECT * FROM users WHERE username='matt' AND password='5657572fc913e2d2a9548ba4f4'
  </code></pre>
  
  <p>From my knowledge I have not done anything wrong in my code but I thought I would ask, since the last time I used <code>MySQL</code> was 2 years ago, things might of changed.</p>
  
  <p>I am wondering what is the error and how do i fix it, I am at the point after googling for the last hour and results saying it was a connection issue and after testing it was connecting to the server correctly (using the hostname not IP address)</p>
  
  <p>The <code>MySQL</code> engine it is using is <code>InnoDB</code> and Collation <code>latin1_swedish_ci</code></p>
  
  <p>code</p>
  
  <pre><code>$r_hostname = "monitor";
  $r_username = "QCSYSTEM";
  $r_password = "123456";
  $link = mysql_connect($r_hostname,$r_username,$r_password);
  $db = mysql_select_db('QCSYSTEM', $link);
  
  $Password = sha1($_POST['password']);
  $username = $_POST['username'];
  
  
  $query = sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'",
           mysql_real_escape_string($username),
           mysql_real_escape_string($Password));
  $result = mysql_query($query,$db);                  
  
  if (!$result) {
      $message  = 'Invalid query: ' . mysql_error() . "\n";
      $message .= 'Whole query: ' . $query;
      die($message);
  } else {
      print "success";                            
  }
  </code></pre>