2017-03-03 23 views
-4
<?php 
session_start(); 
include 'functions/db.php'; 
$strid=$_SESSION['stream']; 
$catid=$_SESSION['category']; 
echo $strid; 
if(isset($_POST['submit'])) 
{ 
    $sql= mysqli_query($con,"SELECT * from questions where strid='$strid'"); 
    $num = mysqli_num_rows($sql); 
    if($num>0) 
    { 
    while($row=mysqli_fetch_assoc($sql)){ 
    extract($row);  
       if(isset($_POST[$row['quesid']])) 
       { 
        $k=$_POST[$row['quesid']]; 
        $v=$row['crsid']; 
        echo $k; 
        echo $v; 
        if($k==1) 
        { 
          $sql="UPDATE tblupdate SET very_interested=very_interested+1 WHERE crsid=$v"; 
          $res=mysqli_query($con,$sql); 
          /* if($res==true) 
          { 
            echo '<script language="javascript">'; 
            echo 'alert("Post Successfully")'; 
            echo '</script>'; 
          }*/ 

        } 



       } 


     } 
    } 
} 

?> 

while循环不重复第二次。和错误警告:mysqli_fetch_assoc()预计参数1被mysqli_result,在C指定的字符串:\ XAMPP \ htdocs中\ p \ forum1 \ next1.php上线13出现警告:mysqli_fetch_assoc()预计参数1被mysqli_result,在C给定的字符串: XAMPP htdocs中 p forum1 next1.php上线13

+1

它很常见的问题....在询问至少搜索之前...您会得到很多类似的问题和答案... – Naincy

+2

可能的[Warning:mysqli \ _fetch \ _assoc()的副本需要参数1为mysqli \ _result,字符串给定](http://stackoverflow.com/questions/36400846/warning-mysqli-fetch-assoc-expects-parameter- 1-to-mysqli-result-string-gi) –

+0

$ sql = mysqli_query($ con,“SELECT * from strid ='”。$ strid。“'”);使用正确的解析 –

回答

-1
You are changing the value of $sql inside the loop.....So in next iteration $sql will be a string instead of mysqli result type.......... 
<?php 
session_start(); 
include 'functions/db.php'; 
$strid=$_SESSION['stream']; 
$catid=$_SESSION['category']; 
echo $strid; 
if(isset($_POST['submit'])) 
{ 
    $sql= mysqli_query($con,"SELECT * from questions where strid='$strid'"); 
    $num = mysqli_num_rows($sql); 
    if($num>0) 
    { 
    while($row=mysqli_fetch_assoc($sql)){ 
    extract($row);  
       if(isset($_POST[$row['quesid']])) 
       { 
        $k=$_POST[$row['quesid']]; 
        $v=$row['crsid']; 
        echo $k; 
        echo $v; 
        if($k==1) 
        {  //Change the name 
          $sql1="UPDATE tblupdate SET very_interested=very_interested+1 WHERE crsid=$v"; 
          $res=mysqli_query($con,$sql1); 
          /* if($res==true) 
          { 
            echo '<script language="javascript">'; 
            echo 'alert("Post Successfully")'; 
            echo '</script>'; 
          }*/ 

        } 



       } 


     } 
    } 
} 

?> 
0

您再次$分配sqlUPDATE查询后您使用它选择查询。这只会造成错误。因为当涉及到第二个循环时,$ sql的值已被更改为。因此它给出了一个致命错误。为更新查询变量提供任何其他名称。 通常不要在同一个文件中使用两次相同的变量名称以及包含的文件

相关问题