FruitFaster Posted May 4, 2013 Share Posted May 4, 2013 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. Link to comment https://forums.phpfreaks.com/topic/277633-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-object-given/ Share on other sites More sharing options...
requinix Posted May 4, 2013 Share Posted May 4, 2013 Take a look at the documentation for mysqli_fetch_array and compare what it says to how you're using it. Spoiler: not all mysqli functions need the $con2. Link to comment https://forums.phpfreaks.com/topic/277633-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-object-given/#findComment-1428257 Share on other sites More sharing options...
FruitFaster Posted May 4, 2013 Author Share Posted May 4, 2013 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! Link to comment https://forums.phpfreaks.com/topic/277633-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-object-given/#findComment-1428259 Share on other sites More sharing options...
FruitFaster Posted May 4, 2013 Author Share Posted May 4, 2013 Okay so I don't get any errors now but it doesn't seem to be inserting the rating or it is inserting 0 over the top of the existing 0. I'm not sure. Link to comment https://forums.phpfreaks.com/topic/277633-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-object-given/#findComment-1428263 Share on other sites More sharing options...
requinix Posted May 5, 2013 Share Posted May 5, 2013 To be sure, what's your code now? Link to comment https://forums.phpfreaks.com/topic/277633-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-object-given/#findComment-1428289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.