php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nakulgoud at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-03 12:54 UTC] nakulgoud at gmail dot com
Description:
------------
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'";
$result=mysql_query($query);
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
} 
$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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-03 14:40 UTC] johannes@php.net
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 http://www.php.net/support.php 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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC