2017-03-03 58 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的值已被更改爲。因此它給出了一個致命錯誤。爲更新查詢變量提供任何其他名稱。 通常不要在同一個文件中使用兩次相同的變量名稱以及包含的文件

相關問題