2017-04-23 77 views
-3

我面臨的一些問題是:警告:mysqli_fetch_array()預計參數1被mysqli_result,在C空給出: XAMPP htdocs中 ...在線路44

說明:未定義變量:信息搜索結果用C :...在線44

警告:mysqli_fetch_array()預計參數1被mysqli_result,在C空給出:...在線44

我不知道如何解決它,任何幫助將不勝感激。由於

generatereport.php

<?php 
if(isset($_POST['search'])) 
{ 
    $courseid = $_POST['courseid']; 
    $query = "SELECT * FROM course_registration WHERE r_cid ='$courseid'"; 
    $searchResult = filterTable($query); 
} 

function filterTable($query) 
{ 
    include("include/config.php"); 
    $filter_Result = mysqli_query($link, $query); 
    return $filter_Result; 
} 
?> 

<fieldset style="font-family: 'Exo', sans-serif;"> 
<legend>Generate Report</legend> 
<form name="GenForm" method="post" action="generatereport.php" onSubmit="return InputCheck(this)"> 
<table> 
    <tr> 
     <td>Course ID:</td> 
     <td><input id="courseid" name="courseid" type="text" class="input" pattern="([A-Z]{3,4})-[A-Z0-9]{3,5}" 
     title="Please enter a valid course id"> 
     <span>(eg. DPT-3054)</span></td> 
    </tr> 
</table> 

    <div> 
     <input type="submit" name="search" value=" Search By Course ID "> 
    </div> 

<table width="70%" cellpadding="5" cellspacing="5"> 
<tr> 
    <th><strong>Course ID</strong></th> 
    <th><strong>Full Name</strong></th> 
    <th><strong>Student ID</strong></th> 
    <th><strong>Program</strong></th> 
    <th><strong>Intake</strong></th> 
</tr> 

<?php while ($row = mysqli_fetch_array($searchResult)) :?> **//line 44 
<tr> 
    <td><?php echo $row['r_cid']; ?></td> 
    <td><?php echo $row['r_name']; ?></td> 
    <td><?php echo $row['r_sid']; ?></td> 
    <td><?php echo $row['r_program']; ?></td> 
    <td><?php echo $row['r_fintake']; ?></td> 
</tr> 
<?php endwhile; ?> 
</table> 

</form> 
</fieldset> 

<script language=JavaScript> 

function InputCheck(GenForm) 
{ 
    if (GenForm.courseid.value == "") 
    { 
    alert("The field Course ID cannot be left blank!"); 
    GenForm.courseid.focus(); 
    return (false); 
    } 
} 

</script> 

的config.php

<?php 

    $link= mysqli_connect("localhost","root","","course_registration_system"); 

?> 
+1

您需要檢查while循環之前的isset。 –

+0

您的進程不是注入安全的,並且您在檢索行之前沒有檢查結果是否爲真/假。您沒有顯示任何調試/錯誤檢查,研究或自我解決的努力。 SO已經爲幾乎所有的事情做出了答案通過在你發佈之前不搜索,你會浪費你的時間和我們的(因爲現在你的重複問題必須審覈)。 Downvoted。 – mickmackusa

回答

1

在您使用

if(isset($_POST['search'])) 
{ 
    $courseid = $_POST['courseid']; 
    $query = "SELECT * FROM course_registration WHERE r_cid ='$courseid'"; 
    $searchResult = filterTable($query); 
} 

因此,這將只設置$信息搜索結果如果$頂部_POST ['search']是se噸。 稍後,如果還設置了此值,則還應該只處理此值。因此,如果(isset($ _ POST ['search'])),表格的生成應該只在一個塊下面。

-1
use this code. i am sure it will be work 
<?php 
if(isset($_POST['search'])) 
{ 
    $courseid = $_POST['courseid']; 
    $query = "SELECT * FROM course_registration WHERE r_cid ='$courseid'"; 
    $searchResult = filterTable($query); 
} 

function filterTable($query) 
{ 
    include("include/config.php"); 
    $display_list=array(); 
    $filter_Result = mysqli_query($link, $query); 
    while ($row = mysqli_fetch_array($filter_Result)) 
    { 
    $display_list[]=$row; 
    } 
    return $filter_Result; 
} 
?> 

<fieldset style="font-family: 'Exo', sans-serif;"> 
<legend>Generate Report</legend> 
<form name="GenForm" method="post" action="generatereport.php" onSubmit="return InputCheck(this)"> 
<table> 
    <tr> 
     <td>Course ID:</td> 
     <td><input id="courseid" name="courseid" type="text" class="input" pattern="([A-Z]{3,4})-[A-Z0-9]{3,5}" 
     title="Please enter a valid course id"> 
     <span>(eg. DPT-3054)</span></td> 
    </tr> 
</table> 

    <div> 
     <input type="submit" name="search" value=" Search By Course ID "> 
    </div> 

<table width="70%" cellpadding="5" cellspacing="5"> 
<tr> 
    <th><strong>Course ID</strong></th> 
    <th><strong>Full Name</strong></th> 
    <th><strong>Student ID</strong></th> 
    <th><strong>Program</strong></th> 
    <th><strong>Intake</strong></th> 
</tr> 

<?php 
if(!empty($searchResult)){ 
foreach($searchResult as $row) { ?> 
<tr> 
    <td><?php echo $row['r_cid']; ?></td> 
    <td><?php echo $row['r_name']; ?></td> 
    <td><?php echo $row['r_sid']; ?></td> 
    <td><?php echo $row['r_program']; ?></td> 
    <td><?php echo $row['r_fintake']; ?></td> 
</tr> 
<?php }} ?> 
</table> 

</form> 
</fieldset> 

<script language=JavaScript> 

function InputCheck(GenForm) 
{ 
    if (GenForm.courseid.value == "") 
    { 
    alert("The field Course ID cannot be left blank!"); 
    GenForm.courseid.focus(); 
    return (false); 
    } 
} 

</script> 
相關問題