Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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...

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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';


  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •