Warning: mysql_result() expects parameter 1 to be resource

Hi there
I am having a problem with this warning message being thrown
Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\css\rnfunctions.php on line 302
and again for line 303 though the funny thing is the code does what its supposed to do I.E change the ‘level’ of user in the database
Here is the code

function receiveuserchange()
{
if (isset($_POST['level'])){
$query = "SELECT * FROM users";
$result=mysql_query($query) or die("Invalid Query : ".mysql_error());
$num=mysql_numrows($result);
$i=0;

while ($i < $num) {

////////////////here are lines 302 and 303///////////////////////////////
$user=mysql_result($result,$i,"user");
$id=mysql_result($result,$i,"id");
/////////////////////////////////////////////////////////////////////////////

if (isset($_POST["$user"])){
$level = ($_POST["$user"]);
$query = "update profiles set level='$level' where pid='$id'";
$result=mysql_query($query) or die("Invalid Query : ".mysql_error());
ViewUsers('viewusers.php');
}else{
echo "$user not recieved";
}
$i++;
}

Can anyone see what the problem is?

In the php manual it says:

[INDENT]Note:
Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set.
[/INDENT]

so chances are it’s the use of mysql_num_rows() that is causing the problem. Is the function intended to modify the level of a single user each time it’s called?

Can you do a SHOW CREATE TABLE for the users and profiles tables? It should be possible to update the users level with a single query

Can you show a

$level = $_POST[‘user’];//like this u can pass the value.

$query = “update profiles set level=‘$level’ where pid=‘$id’”;

In this query, level value is not updating, because $level value is not set…

Probably, because you pass $result as parameter 1, when $result is the result of an Update query. In this case your result will be True upon successful update.
You can find more information here.

Amit Yaron and venkat6134: the query thats having problems is actually the first query which is a SELECT not an UPDATE query.

$num=mysql_numrows($result);
here is the problem; $num is not set.
correct it by;
$num=mysql_num_rows($result);

It seems like you haven’t yet understood completely how to query a database and then loop through the result set to fetch and elaborate the extracted data.
Please take a look at the manual: http://www.php.net/manual/en/function.mysql-fetch-assoc.php

If it’s still not clear, don’t hesitate to ask more questions :slight_smile:

Thanks guido2004
It works fine now.
And thanks everyone else for trying to help.