警告:mysqli_fetch_row()期望参数1为mysqli_result

时间:2013-11-01 04:08:03

标签: php mysql

我很抱歉我提问,我对php和mysql相当新,我对理解调试还是比较新的。我创建了这个添加成员/朋友文件,并且进程文件有错误

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in line 57  

$countArr = mysqli_fetch_row($countResult2);

我也收到了这个错误

Warning: Cannot modify header information - headers already sent by 

这是标题:位置部分,香港专业教育学院搜索如何修复此问题,但我不明白 如果这是解决问题的正确方法,如何实现ob_start();代码。

有人知道为什么会这样吗?如果是的话,你能解释一下吗?非常感谢你

下面是代码,名为memberaddprocess.php

 <?php
//////////////////////////////////////
    session_start();
    require_once('sqlconnect.inc.php');
/////////////////////////////////////

    $memberHid1 = $_POST['memberHid1'];  
    $new_session = $_POST['memberHid']; 
//connecting to the database
$conn = @mysqli_connect($host, 
        $user, 
        $pswd, 
        $dbnm);

    if (!$conn) {
        echo "<p>Database connection failure</p>"; 
    } else {

    @mysqli_select_db($conn, $dbnm)
        or die ("Database 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
     exit();

?>

1 个答案:

答案 0 :(得分:0)

我认为这会对你有所帮助

 <?php 
          $query4 = "SELECT member_id2
                    FROM myteam 
                    WHERE friend_id1 = '$pst'";

        $countResult2 = @mysql_query($query4,$conn);
        $countArr = mysql_fetch_array($countResult2);
        echo $countArr['member_id2'];
    ?>