Page 1 of 1

Warning: mysql_result() expects parameter 1 to be resource

PostPosted: 18. February 2016 19:07
by BrooksyFC
Hi there. I am having a problem with my code. This is the error I am having:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Functions\Users.php on line 5


This is the code which the error is appearing from but I can't work out what is going wrong.

Code: Select all
<?php
function user_exists($username) {
   $username = sanitize($username);
   $query = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'username' = '$username'");
   return (mysql_result($query, 0) == 1) ? true : false;
}
?>


Thanks in advance

Re: Warning: mysql_result() expects parameter 1 to be resour

PostPosted: 18. February 2016 20:22
by Altrea
Hi,

make use of the mysql error functions on every code part mysql errors can occure.
http://php.net/manual/de/function.mysql-error.php

But i give you a hint: single quotes ( ' ' ) are not always the correct wrapping character. For database names, database field names, etc you need to use backticks ( ` ` ).
Use single quotes only on string values.

best wishes,
Altrea