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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.