Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2012, 04:37 AM   PM User | #1
dunhillx69
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dunhillx69 is an unknown quantity at this point
Exclamation Need Help!! mysql_result() [function.mysql-result]

hi guys... i need help with this coding... i had this error message while running the php..

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in C:\wamp\www\25122011\files.php on line 160.

And here is the coding from line 156-179:

Code:
              <?PHP
			   include("connect.php");
	$fnn = $_POST['finoname'];
	$query = mysql_query("SELECT * FROM files WHERE fileno = '$fnn' ");
			$fno = mysql_result($query,0,0);     
 		  	$fname = mysql_result($query,0,1);         
		  	$floc = mysql_result($query,0,3);
				$fres = mysql_result($query,0,5);
	$query2 = mysql_query("SELECT * FROM files WHERE filename = '$fnn' ");
			$fno2 = mysql_result($query2,0,0);     
 		  	$fname2 = mysql_result($query2,0,1);         
		  	$floc2 = mysql_result($query2,0,3);
			$fres2 = mysql_result($query2,0,5);	
	$idindb = mysql_query("SELECT * FROM files WHERE filename = '$fnn' OR fileno = '$fnn' ");
	$isidindb = mysql_num_rows($idindb);
	
	if ($fnn == ''){
		echo "<font color='red'>Please make sure the finoname is correct.</font>";
		} else
		if ($isidindb == 0){
		echo "<font color='red'>No record found for that finoname</font>";
		}else {			
		echo"<b><font color='red'> $fno$fno2 - $fname$fname2 - $floc$floc2 - $fres$fres2 </font></b>";}
			?>
million thanks in advance...
dunhillx69 is offline   Reply With Quote
Old 01-06-2012, 04:46 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Your queries are likely failing so do some error checking, change your code to the following and post your results.
PHP Code:
<?PHP
               
include("connect.php");
    
$fnn $_POST['finoname'];
    
$query mysql_query("SELECT * FROM files WHERE fileno = '$fnn' ") or die(mysql_error().'<br>query');
            
$fno mysql_result($query,0,0);     
               
$fname mysql_result($query,0,1);         
              
$floc mysql_result($query,0,3);
                
$fres mysql_result($query,0,5);
    
$query2 mysql_query("SELECT * FROM files WHERE filename = '$fnn' ") or die(mysql_error().'<br>query2';
            
$fno2 mysql_result($query2,0,0);     
               
$fname2 mysql_result($query2,0,1);         
              
$floc2 mysql_result($query2,0,3);
            
$fres2 mysql_result($query2,0,5);    
    
$idindb mysql_query("SELECT * FROM files WHERE filename = '$fnn' OR fileno = '$fnn' ") or die(mysql_error().'<br>idindb query');
    
$isidindb mysql_num_rows($idindb);
    
    if (
$fnn == ''){
        echo 
"<font color='red'>Please make sure the finoname is correct.</font>";
        } else
        if (
$isidindb == 0){
        echo 
"<font color='red'>No record found for that finoname</font>";
        }else {            
        echo
"<b><font color='red'> $fno$fno2 - $fname$fname2 - $floc$floc2 - $fres$fres2 </font></b>";}
            
?>
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-06-2012, 06:16 AM   PM User | #3
dunhillx69
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dunhillx69 is an unknown quantity at this point
thanks for your reply... but it seems like it doesn't solve the issue... the error remain the same as follows;

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in C:\wamp\www\25122011\files.php on line 160
dunhillx69 is offline   Reply With Quote
Old 01-06-2012, 04:20 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Not necessarily failing, the above error indicates its more likely that there are simply no results.
You'll need to make use of mysql_num_rows to check if you can actually move to a record before attempting to retrieve it.

I'm a little curious as to why you have three queries to effectively do the same thing. fileno sounds to me like an integer versus the filename of a string. I wouldn't use the OR statement here, since I could have a filename 1 and a fileno 1 if this assumption is correct. This would assume that filename and fileno do not need to correspond, so you could have unintended results.
If fileno is a number, check it as such first:
PHP Code:
if (isset($_POST['finoname']))
{
    
$sProvided $_POST['finoname'];
    
$sQry 'SELECT * FROM files';
    if (
is_numeric($sProvided))
    {
        
$sQry .= ' WHERE fileno = ' . (int)$sProvided;
    }
    else
    {
        
$sQry .= ' WHERE filename = \'' mysql_real_escape_string($sProvided) . '\'';
    }

    
$idindb mysql_query($sQry) or die(mysql_error());
    if (
mysql_num_rows($idindb) > 0)
    {
        list(
$fno$fname$floc$fres) = mysql_fetch_row($idindb);
    }
    else
    {
        print 
'no results';
    }
}
else
{
    print 
'nothing to query';

Fou-Lu is offline   Reply With Quote
Old 01-07-2012, 03:29 AM   PM User | #5
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Quote:
Originally Posted by dunhillx69 View Post
thanks for your reply... but it seems like it doesn't solve the issue... the error remain the same as follows;

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in C:\wamp\www\25122011\files.php on line 160
I never said it was going to "solve" the issue.

We needed to rule out that your queries weren't failing.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-07-2012, 04:26 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Also, since aero replied I realized I biffed something too. With my code rather than having a potential of 2 results with a filename and fileno being the same, I now have only the ability to fetch the fileno instead of the filename, which is actually worse IMO.
So in hinds sight, the OR is probably the best choice here, and use a loop to check the results.

Aero's still right when it comes to some sort of error handling, whether it be a die or something more graceful. You should always check that something does exist off of a resource. Fortunately, resources will return false (or null in some situations) if they fail. So using fopen or mysql_query or whatever can be checked with a simple assignment and if if you would like:
PHP Code:
if ($qry mysql_query($sQry))
{
    
// good, keep going
}
else
{
    print 
'Oops, something went wrong with site.  Please check back later';

for example.
Since these are external, you don't want PHP to deal with this itself. This is much like throwing an exception; pass the buck back to the caller to determine how to deal with the failure.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
error, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 PM.


Advertisement
Log in to turn off these ads.