View Full Version : Warning: mysql_result(): supplied argument is not a valid MySQL result resource in...

11-12-2011, 10:16 AM
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/******/domains/*********.***.**/public_html/admin/func/user.func.php on line 10
Unable to log you in
(*-is hidden by me)


function logged_in() {
return isset($_SESSION['id']);

function login_check($username, $password) {
$username = mysql_real_escape_string($username);
$login_query = mysql_query("SELECT COUNT(`id`) AS `count`, `id` FROM `config` WHERE `username` = '$username' AND `password` = '".md5($password)."'");
return (mysql_num_rows($login_query, 0) == 1) ? mysql_num_rows($login_query, 0, 'id') : false;

function user_data() {
$args = func_get_args();
$fields = '`'.implode('`, `', $args).'`';

$query = mysql_query("SELECT $fields FROM config WHERE id = '".$_SESSION['id']."'");
$query_result = mysql_fetch_assoc($query);
foreach ($args as $field) {
$args[$field] = $query_result[$field];
return $args;

function genRandomString() {
$length = 10;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters) -1)];
return $string;

Line 10:

return (mysql_num_rows($login_query, 0) == 1) ? mysql_num_rows($login_query, 0, 'id') : false;

I can't log in :mad:

11-12-2011, 04:40 PM
You're usage is wrong, but the error doesn't match your code. The line does, and the actual syntax error appears to as well, so methinks its been modified since providing it here.
You cannot use mysql_num_rows with a second parameter (or third). It only takes a resource. A count will always provide at least 1 record. Given the error you have, I expect that this is actually mysql_result, which does accept a second parameter to indicate the field (and matches your error itself). Dropping the count aggregate seems easier, then you can just count the results with mysql_num_rows, which should be 1 or 0. If its more than one, you have a unique constraint issue on your hands since it allows multiple users with the same username and password (which chances are you will not have).

The error you have overall is a failure of your query itself. Since the variable names are correct, that indicates that the result of a mysql_query has returned false, which in the event of a select is a SQL syntax error. Check your column names to verify. You can add an or die(mysql_error()); chain to the mysql_query itself to dump a mysql error on a failure.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum