Solved

MySQL_result warning: "Unable to jump to row 0 on MySQL result"

Posted on 2010-09-15
15
629 Views
Last Modified: 2013-12-13
Hi,

I have a very limited knowledge of MySQL, and am working off php code created by somebody else. The company I work for has an annual vote, which members can register to do online if they wish. As the registration process begins soon, I have been testing this today. It might also be worth noting the company uses Joomla.

I am testing the functionality of the Vote Registration form, which is where the problem occurs. After making the relevant pages live, the opening page (where members input their details if they wish to vote online when the opportunity arises) opens with a warning message. It reads:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 158 in /home/directorsukcom/public_html/forms/votereg.php on line 25

I found the votereg.php form, and the 25th line. This is the info from lines 7-29:

<?php
$user =& JFactory::getUser();
$userId = $user->get('username');
$userNumber = $user->get('id');
$mineid=$userId;

$db =& JFactory::getDBO();


$query = "SELECT * from jos_boarddates ORDER BY year DESC";
$db->setQuery($query);
$row = $db->loadObject();
$open = $row->open;
$close = $row->close;
$regclose = $row->regclose;

$sql = "SELECT * from jos_dprsprofile WHERE userid = '$userNumber'";
$r = mysql_query($sql);
$voting = mysql_result($r, 0, 'vote_online');



?>

Line 25 is in bold ($voting = mysql_result($r, 0, 'vote_online');). Having looked at JoomMyAdmin > PhPMyAdmin Control Panel, I found the form jos_dprsprofile. As 168 people chose to vote online last year, those same people have a yes in the vote_online column. My understanding is these people mistakenly registered to vote online again, they would be told that they've already registered. But I don't see why this should cause the warning message - perhaps it's not functioning as it should.

I hope I've given enough information, but please let me know should you need more. I would appreciate an answer soon.

Thanks,

RD
0
Comment
Question by:rick_danger
[X]
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
  • 8
  • 7
15 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33681750
to jump to the "first" record, there has to be a record...
so you have to test first:
$r = mysql_query($sql);
if (mysql_num_rows($r) == 0)
{
  $voting = "0";
}
else
{
  $voting = mysql_result($r, 0, 'vote_online');
}

Open in new window

0
 

Author Comment

by:rick_danger
ID: 33681793
Thanks, Angell. Does it matter where I put this code?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33681813
you put that instead of the 2 lines of code you have...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rick_danger
ID: 33681821
Sorry, so over: $r = mysql_query($sql);
$voting = mysql_result($r, 0, 'vote_online');

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33681835
yes, exactly
0
 

Author Comment

by:rick_danger
ID: 33681906
Great, that's got rid of the warning message. Thanks.

Can I be sure that changing the code won't have any undesired bearings on the voting process? After people have registered, there is obviously the chance to vote itself which depends on other forms and information (sorry if this is vague!) - changing this code won't compromise or disrupt this, will it?
0
 

Author Comment

by:rick_danger
ID: 33682065
Hi, are you still able to help? There's still the problem of people registering multiple times, or those who registered last year mistakenly re-registering again this year.

Would very much appreciate further assistance.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33682184
it should not disrupt ...

but as you said, it's quite vague, so I don't know how you determine that the "people" are the same than "last year" ...
0
 

Author Comment

by:rick_danger
ID: 33682249
Well we keep a record of people (lets call them members, it's more accurate) who have registered to vote online in our database. The database is linked to the website.

Going back to the php, on line 82 of the original form there is the following:

<? if ($voting == 'yes') { echo "You have already registered to vote online.Please return to the site between <? echo $open; ?> and <? echo $close; ?> to cast your vote. If this is incorrect, please email the communications team through communications@directors.uk.com"; } ?>

<? if ($voting != 'yes') { ?>

I think the code you gave me earlier now negates that message, as I'm able to register multiple times. Could you help with this please?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33682318
surely "my" code does not negate yours you show there...

of course, you might put "no" and not "0", but both values will not be equal to "yes" ...

I presume there must be other lines that are filled from this record, which should be "initalized" the same way as the $voting if there is no record ...

please double-check
$r = mysql_query($sql);
if (mysql_num_rows($r) == 0)
{
  $voting = "no";
}
else
{
  $voting = mysql_result($r, 0, 'vote_online');
}

Open in new window

0
 

Author Comment

by:rick_danger
ID: 33682588
Ok, thanks for that. Having spoken to my colleague I may have got slightly confused with this, so in fact your new code may have been all that was needed. I'll let you know shortly.

Can I just ask what your new code added that was absent from the original? Thanks.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33682642
the code added the control if there is a record returned or not ...
without that, and the "error ignored", you may get "obscure" side effects (because of NULL value processing ...)
0
 

Author Comment

by:rick_danger
ID: 33682709
Right, so that's probably what caused the warning then?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33682781
exactly
0
 

Author Comment

by:rick_danger
ID: 33683074
Just spoken to my colleague and all's now working as it should.

Thanks for all your help. I'm happy to award the points to you.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
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…

756 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