Solved

mysql index warning error

Posted on 2011-03-02
12
306 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:peter_coop
ID: 35020600
@KazooSoft

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

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 108

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 108

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 108

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now