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:
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.