firehawk777 Posted February 8, 2011 Share Posted February 8, 2011 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 https://forums.phpfreaks.com/topic/227033-warning-mysql_result-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
micmania1 Posted February 8, 2011 Share Posted February 8, 2011 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 https://forums.phpfreaks.com/topic/227033-warning-mysql_result-expects-parameter-1-to-be-resource-boolean-given/#findComment-1171379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.