Jump to content

mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given


Go to solution Solved by FruitFaster,

Recommended Posts

I'm making a page that takes user comments and outputs them on another page where they can be rated from 1-10. I'm having trouble with myqli_fetch_array ...it says:


mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in      /place where it found it

 

 

The code I have is:

<?php

$con2=mysqli_connect("host.com","user","pwd","dbase");

  // Check connection
if (mysqli_connect_errno($con2))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  
  
  }
  $value=$_POST['rating'];
  $id=$_POST['id'];
  
  
   mysqli_query  ($con2, "UPDATE table SET totalraters = totalraters + 1 WHERE id='$id' ");
   mysqli_query  ($con2, "UPDATE table SET ratingsum = ratingsum + '$value' WHERE id='$id' ");
   
  
  
  
  $query2 = "SELECT ratingsum, totalraters FROM table WHERE id='$id' ";
  $result2=mysqli_query($con2, $query2);
  while  ($row2= mysqli_fetch_array($con2, $result2))
  
  {

  $ratingsum=$row2['ratingsum']; 
  $totalraters=$row2['totalraters'];
  
   
  IF  ($totalraters != 0)  {
  ($rating = round($ratingsum/$totalraters));
  mysqli_query ($con2, "INSERT INTO table (rating) VALUES ($rating) WHERE id='$id' ");}
  
  
  
  include ('index.html');


}

?>  

The id is sent by post from the previous php file that has a form. It updates the database with everything but the final rating and works up to the mysqli_fetch_array fine. Any help appreciated. I've spent a lot of time reading documentation and googling and changing millions of things. At first I had the boolean error now this. I have no clue why.

Thankyou most kindly requinix. To be honest I think I could have stared at it for hours and not seen it. What's worse is the previous php file has exactly the same type of array in it. Just not seeing the woods for the trees. Again, thankyou!

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.