Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

mysql index warning error

Posted on 2011-03-02
12
310 Views
Last Modified: 2012-08-13
hello

i am seeing this error when i submit data to db and do not know how to correct it.

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 103.

this points to line 40 in the posted code. it is however inserting the data correctly.  i would be grateful if someone could point out how to correct this error.many thanks
<?php 
				function get_btref(){
				$company = $_SESSION['kt_idcom_usr'];
				$sql = 'select btref'
				. ' from boxes'
				. " where customer = '$company'"
				. ' order '
				. ' by id desc'
				. " limit 1";
				$result = mysql_query($sql);
				$btref = mysql_result($result,0,"btref"); <--- LINE 40
				return $btref + 1;} 
?>

Open in new window

0
Comment
Question by:peter_coop
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 4

Expert Comment

by:KazooSoft
ID: 35019353
Are you certain that query returns any rows?
0
 

Author Comment

by:peter_coop
ID: 35019740
hi

i have tried echo $result and that produces Resource id #103. what i was expecting to see was a number like 4646.
0
 
LVL 4

Expert Comment

by:KazooSoft
ID: 35019933
Can you run the query in something like phpmyadmin or directly on the server?

Try this instead of echo the "result

print_r(mysql_fetch_assoc($result));
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4

Expert Comment

by:KazooSoft
ID: 35019935
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35020098
After this

$result = mysql_query($sql);


Add this

echo "This will return ".  mysql_num_rows( $result )  ." rows";


and you may as well alter the query to

$result = mysql_query($sql) or die( mysql_error() );

0
 

Author Comment

by:peter_coop
ID: 35020573
@bportlock

result: This will return 0 rows. thanks

@KazooSoft

it printed nothing at all. thanks
0
 

Author Comment

by:peter_coop
ID: 35020600
@KazooSoft

if i run command through myphpadmin it shows correct data in window. thanks
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35021052
>i have tried echo $result and that produces Resource id #103.
means that the query run successfully. does not mean it actually returned rows
the output of mysql_num_rows returning 0 confirms that

>what i was expecting to see was a number like 4646.
means that somehow the query is wrong, or you connect to another database, or it's not the correct SESSION data you get.
print $sql to "see" the query before running it.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 35023101
This is obviously untested - I do not have your data base, but I think it might give you what you want, or at least the diagnostic information you need.
<?php // RAY_temp_petercoop.php
error_reporting(E_ALL);


// MODIFIED FROM THE ORIGINAL POST AT EE
function get_btref()
{
    $company = $_SESSION['kt_idcom_usr'];
    $sql = 'SELECT btref'
    . ' FROM boxes'
    . " WHERE customer = '$company'"
    . ' ORDER BY id DESC'
    . ' LIMIT 1
    ;
    $res = mysql_query($sql);
    if (!$res)
    {
        echo "<br/>FAIL: $sql<br/>";
        die( mysql_error() );
    }
    
    $num = mysql_num_rows($res);
    echo "<br/>QUERY FOUND $num ROWS";
    
    $row = mysql_fetch_assoc($res);
    $btr = $row["btref"];
    return $btr + 1;
}

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35023109
Add ending apostrophe on line 13.  Feel free to add conditional logic instead of the echo on line 23.
0
 

Author Closing Comment

by:peter_coop
ID: 35025979
thanks ray. this helped me visualise the flow of the logic and now i can move forward. thank you
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35026070
Thanks for the points.  Data visualization is almost always helpful!  Best regards, ~Ray
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question