我面临一些问题:
注意:未定义的变量:第44行的C:...中的searchResult
警告:mysqli_fetch_array()要求参数1为mysqli_result,在第44行的C:...中给出为null
我不知道如何解决它,我们将非常感谢任何帮助。感谢
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");
?>
答案 0 :(得分:1)
在顶部使用
if(isset($_POST['search']))
{
$courseid = $_POST['courseid'];
$query = "SELECT * FROM course_registration WHERE r_cid ='$courseid'";
$searchResult = filterTable($query);
}
因此,如果设置了$ _POST [&#39; search&#39;],则只会设置$ searchResult。 稍后,如果还设置了此值,则还应仅处理此值。因此,当if($ _ POST [&#39; search&#39;])
时,表的生成应该只在一个块内。答案 1 :(得分:-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>