I don't know what this error meas as I just started working with databases and MySQL. The warning is this:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\surveyresults.php on line 57

And the code is this:

function update_database($newdata)
{
  	$connection = mysql_connect("localhost","root");
 	 mysql_select_db("teachersurvey", $connection);

 for ($rownumber=1; $rownumber<=6; $rownumber++)
 {
  	$myquery= "SELECT * FROM teacher where pid=".$rownumber;
                  $result = mysql_query ($myquery, $connection);        //this is line 57
    $row = mysql_fetch_array($result);	# grab one row of the table
	for ($j=1; $j<=4; $j++)
	{
		$scorehandle="score".$j;
		$count[$j]=$row[$scorehandle];
		debug("in row $rownumber, score $j was:".$count[$j]);
	}
	# Now, increment the count, based on the current product's results\
	$score=$newdata[$rownumber];
	if ($score>=1 && $score<=4)	# Safety check
	{
		$count[$score]++;
		debug("score=$score, count= ".$count[$score]);

		# Now, write that row information back into the database
		$putquery="UPDATE teacher SET score".$score." = ".
			$count[$score]." where pid=".$rownumber;

		debug("the put query:".$putquery);
		$result= mysql_query ($putquery, $connection);
	}
	

Thank you in advance

    add some debugging such as:

     $result = mysql_query ($myquery, $connection) or die(mysql_error());
    

      Reason: on error, mysql_... returns boolean false, not a resource.

        Maybe add a password to mysql_connect in your $connection variable...

        <?php
        function update_database($newdata) {
          $connection = mysql_connect("localhost","root","password") or die('Cannot connect: '.mysql_error());
          $db         = mysql_select_db("teachersurvey", $connection) or die('Cannot select database: '.mysql_error());
        
          for ($rownumber=1; $rownumber<=6; $rownumber++) {
            $myquery = "SELECT * FROM teacher where pid=".$rownumber;
            $result  = mysql_query($myquery);        //this is line 57
            $row     = mysql_fetch_array($result);    # grab one row of the table
            for ($j=1; $j<=4; $j++) {
              $scorehandle = "score".$j;
              $count[$j]   = $row[$scorehandle];
              debug("in row $rownumber, score $j was:".$count[$j]);
            }
            mysql_free_result($result);
            # Now, increment the count, based on the current product's results\
            $score = $newdata[$rownumber];
            if ($score>=1 && $score<=4) {    # Safety check
              $count[$score]++;
              debug("score=$score, count= ".$count[$score]);
        
          # Now, write that row information back into the database
          $putquery = "UPDATE teacher SET score".$score." = ".$count[$score]." WHERE pid=".$rownumber;
        
          debug("the put query:".$putquery);
          $result = mysql_query($putquery);
        }
        mysql_free_result($result);
          }
          mysql_close($connection);
        }
        

          That message means that your database result comes back as FALSE, which is not a connection resource. First, check that you are connecting to your database. Then check that you are passing the connection resource.

            Write a Reply...