Warning: mysql_result() expects parameter 1 to be resource

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Warning: mysql_result() expects parameter 1 to be resource

Postby BrooksyFC » 18. February 2016 19:07

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
BrooksyFC
 
Posts: 1
Joined: 18. February 2016 18:59
Operating System: Windows 10

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

Postby Altrea » 18. February 2016 20:22

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 105 guests