Jump to content

Warning: mysql_result() expects parameter 1 to be resource, boolean given


firehawk777

Recommended Posts

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

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?

You have an update in the same loop as your mysql_result().

 

So the first time it loops, you'll be using mysql_result($result) correctly, but then it will continue until the next query where it will set $result as another type of resource.

 

Try changing your second result variable to $result2.

 

 

On another note, looping through running multiple queries is not good practice as it is quite server-insensive. Try looking at the SQL IN function which will need less queries.

 

http://techonthenet.com/sql/in.php

 

The link shows SELECT examples but can be used with UPDATE also.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.