This question already has an answer here:
ERROR:
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'
From my knowledge I have not done anything wrong in my code but I thought I would ask, since the last time I used MySQL
was 2 years ago, things might of changed.
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)
The MySQL
engine it is using is InnoDB
and Collation latin1_swedish_ci
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() . "
";
$message .= 'Whole query: ' . $query;
die($message);
} else {
print "success";
}
</div>
The second argument to mysql_query
should be a link identifier. You are using $db
as the second argument, which is nothing but a boolean value. Try this..
$result = mysql_query($query,$link);
or just don't pass any second argument.