|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50642 'if(!$result)'
Submitted: 2010-01-03 12:54 UTC Modified: 2010-01-03 14:40 UTC
From: nakulgoud at gmail dot com Assigned:
Status: Not a bug Package: *Database Functions
PHP Version: 5.3.1 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2010-01-03 12:54 UTC] nakulgoud at gmail dot com
After exection of query where mysql returns an empty set then  'if($result)' returns true.It should return false.How to handle this situation. 

Reproduce code:
From manual page: function.mysql-fetch-row#Examples
$query="select name from user where id=42'";
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
$data = MYSQL_RESULT($result,0,"id");

Expected result:
Could not run query : No such row in database.

Actual result:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\all is well\signin.php on line 6


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-03 14:40 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

our check for if (!$result) checks whether the query was successfulwhichit was, as it returned a reslt set of 0 elements. You might use  mysql_num_rows() to see how many rows there are, while in general it's better to use mysql_fetch() instead of mysql_result(). Please also note that the mysqli extension offers support for MySQL features and is the suggested way to talk to MySQL.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 10 19:01:25 2020 UTC