Solved

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

Posted on 2010-09-15
15
612 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
  • 8
  • 7
15 Comments
 
LVL 142

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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33681813
you put that instead of the 2 lines of code you have...
0
 

Author Comment

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

0
 
LVL 142

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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 142

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 142

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 142

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 142

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 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

14 Experts available now in Live!

Get 1:1 Help Now