[solved] getting a value (error)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

[solved] getting a value (error)

Post by d3ad1ysp0rk »

Code: Select all

<?PHP
if($usr!=""){
$username="******";
$password="******";
$database="******";
$dbconnect=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$ranksql = "SELECT `rank` FROM `phpbb_users` WHERE `username` = '$usr' LIMIT 1";
$rank = mysql_result(mysql_query($ranksql), 0,0); //line 9
echo $rank;
}
else{
echo "crap.";
}
?>
i enter the URL (getrank.php?usr=someone) and it gives me this:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/gamegate/public_html/getrank.php on line 9
Line 9: $rank = mysql_result(mysql_query($ranksql), 0,0);

I have no idea why this is happening.. i copied it almost exactly from my other script (for my other site) which works, and it doesnt work on this one

at first it wouldnt connect, but then i fixed that, and now this is happening..

thanks for any help
Last edited by d3ad1ysp0rk on Sun Nov 23, 2003 10:51 pm, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Where to you get $usr from - and do you have register globals off now but it was on before?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

right now im testing my script, so i just enter getrank.php?usr=username

and i havent touched register globals..

i dont know if they're on or not (this isnt my host, im making this site for someone else)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

register_globals On On
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Try rewriting the script a little defining a $query var to pass to mysql_result and change mysql_query to print some error info:

Code: Select all

<?php

$query = mysql_query($ranksql) or die('Error: ' . mysql_errno() . ' - ' . mysql_error() . '<br/>' . $ranksql . '<br />');

$rank = mysql_result($query, 0,0);

?>
Last edited by McGruff on Wed Aug 10, 2005 8:52 am, edited 1 time in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

wow i feel so dumb.. my varname in the DB was 'siterank', NOT 'rank' .. lol

thanks for your help
Post Reply