warning with mysqli_fetch_row expects parameter 1

Hi guys,

I am struggling why I received the error, my apology, I am fairly new using php and mysql

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in line 57
which is in my code is the $countArr = mysqli_fetch_row($countResult2);

and I’ve received this error
Warning: Cannot modify header information - headers already sent by (output started at on line 98
which is the header(‘Location: memberadd.php’);
to fix it i search it uses ob_start() but i am not sure how i could implement this to the code

Anyone understood why it is like this? if so, could you please kindly explain.
thanks, greatly appreciated!

below is the code:

[php]<?php
//////////////////////////////////////
session_start();
require_once(‘sqlconnect.inc.php’);
/////////////////////////////////////

$memberHid1 = $_POST['memberHid1'];  
$new_session = $_POST['memberHid']; 

//connecting to the database
$conn = @mysqli_connect(“mysql.ict.swin.edu.au”,“s7259476”,“291090”)
or die(“

The server not available

”);
//selecting database
$selectDatabase= @mysqli_select_db($conn,“s7259476_db”)
or die(“

The database is not available.

”);
$query = "SELECT member_id 
		  FROM team 
		  WHERE member_name = '$memberHid1'";
		  
$queryResult = @mysqli_query($conn, $query)
			or die ("<p>Unable to execute query.</p>". "<p>Error code:" . mysqli_errno($conn) .":" . mysqli_error($conn));

$fetchArr = mysqli_fetch_row($queryResult);

$memberHid3 = $fetchArr[0];				
$memberHid = $_SESSION['membername'] = $new_session;

$query2 = "SELECT member_id 
		   FROM team 
		   WHERE member_name = '$memberHid'";
		   
$queryResult2 = @mysqli_query($conn,$query2)
	or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn));
	
$fetchArr2 = mysqli_fetch_row($queryResult2);
$memberHid4 = $fetchArr2[0];

$query3 = "INSERT INTO myteam 
		   VALUES($memberHid4, $memberHid3)";
		   
$queryResult3 = @mysqli_query($conn,$query3)
	or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";
			echo "<p>$memberHid1"."  "." Successfully added</p>";

	$queryCount = "SELECT COUNT(*) 
				   FROM team";
	$countResult = @mysqli_query($conn,$queryCount);
	$fetchCountArr = mysqli_fetch_row($countResult);	
	for($n=0;$n<$fetchCountArr[0];$n++)
	{
		$pst = $n+1;
		$query4 = "SELECT member_id2
					FROM myteam 
					WHERE friend_id1 = '$pst'";
					
		$countResult2 = @mysqli_query($conn,$query4);
		$countArr = mysqli_fetch_row($countResult2);
		$a=0;
		while($countArr)
		{
			$a++;
			$countArr = mysqli_fetch_row($countResult2); //echo "<p>$a</p>";
		}
		
		$query4 = "UPDATE team 
				   SET num_of_members= '$a' 
				   WHERE member_id = '$pst'";
				   
		$countResult2 = @mysqli_query($conn,$query4);
	
	}

$querySelect = "SELECT member_id2 
				FROM myteam 
				WHERE member_id1 = '$memberHid4'";
				
$querySelectResult = @mysqli_query($conn, $querySelect);
$fetchArr = mysqli_fetch_row($querySelectResult);

while($fetchArr)
{
	foreach($fetchArr as $value)
	
	{
		//echo $value;
		$querySelect2 = "SELECT member_name 
						FROM friends where friend_id='$value'";
		$querySelectResult2 = @mysqli_query($conn, $querySelectResult2);
		$fetchArr2 = mysqli_fetch_row($querySelectResult2);
		foreach($fetchArr2 as $value)
		{
			//echo $value;
		}		
	}
	$fetchArr = mysqli_fetch_row($querySelectResult);
}
		
 header('Location: memberadd.php'); //redirecting to home page

?>[/php]

You shouldn’t suppress errors as it is impossible to figure out what’s wrong.

[php]
$query4 = “SELECT member_id2
FROM myteam
WHERE friend_id1 = ‘$pst’”;

$countResult2 = @mysqli_query($conn,$query4); // <-- probably some kind of error here, so $countResult2 is returning a bool (false)
$countArr = mysqli_fetch_row($countResult2);[/php]

  1. Handle errors, don’t suppress them.
  2. Use prepared statements, your queries are vulnerable for sql injection.
Sponsor our Newsletter | Privacy Policy | Terms of Service