如何删除此php脚本中的此警告
我有一个php查询,它连接了许多表(从baby类到standard seven),这样我就可以得到每个表的总和 但当我运行查询时,它会给我一个警告如何删除此php脚本中的此警告,php,Php,我有一个php查询,它连接了许多表(从baby类到standard seven),这样我就可以得到每个表的总和 但当我运行查询时,它会给我一个警告 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\db_valentine_V2\Templates\school_income.php on line 872 我试图在第872行中找出这个脚本的位置
Warning: mysql_fetch_array() expects
parameter 1 to be resource, boolean given in
C:\wamp\www\db_valentine_V2\Templates\school_income.php on line 872
我试图在第872行中找出这个脚本的位置
while($res=mysql_fetch_array($q)){
有人能帮我消除这个警告吗?它真的花了我很长时间却没有成功
<?php
$date="date";
$class="class";
$database=("mcl");
mysql_connect("localhost","root","mcl");
@mysql_select_db(mcl) or die( "Unable to select database");
if(isset($_REQUEST['submit'])){
$class=$_POST['class'];
$date=$_POST['date'];
$sql="SELECT SUM(Total) FROM
( SELECT
SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee+
uniform_fee+sport_uniform) As Total FROM payment UNION
SELECT SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+
food_fee+uniform_fee+sport_uniform) As Total FROM payment_one UNION
SELECT SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee
+uniform_fee+sport_uniform) As Total
FROM payment_two UNION
SELECT SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee
+uniform_fee+sport_uniform) As Total
FROM payment_three UNION
SELECT
SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee+
uniform_fee+sport_uniform) As Total
FROM payment_four UNION
SELECT SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee+
uniform_fee+sport_uniform) As Total
FROM payment_five UNION
SELECT SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee+
uniform_fee+sport_uniform) As Total
FROM payment_six UNION
SELECT SUM(school_fee+trans_fee+reg_fee+edutrip_fee+stationery_fee+food_fee+
uniform_fee+sport_uniform) As Total
FROM payment_seven )a)";
$q=mysql_query($sql);
}
?>
<form method="post">
<table width="500" border="0">
<tr>
<td>Class</td>
<td><input type="text" name="class" value="<?php echo $class;?>" /></td>
<td>Year</td>
<td><input type="number" name="date" value="<?php echo $date;?>" /></td>
<td><input type="submit" name="submit" value="Search" /></td>
</tr>
</table>
<br />
</form>
<table>
<h4>
This is total amount of money payed by <?php echo $class;?>  class
in <?php echo $date;?> </h4><hr>
<table width="700" border="0" height="2" cellpadding="0" cellspacing="1" >
<tr>
<td bgcolor="#FF9900" width="50">Class</td>
<td bgcolor="#FF9900" width="300">Total amount of money payed</td>
</tr>
<?php
while($res=mysql_fetch_array($q)){
?>
<tr>
<td width="100"><?php echo $res['class'];?></td>
<td width="200"><?php echo $res['SUM(Total)'];?></td>
</tr>
<?php }?>
</table>
等级
试试这样的方法
if($q === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($res=mysql_fetch_array($q))
{
//do here
}
试试这样的
if($q === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($res=mysql_fetch_array($q))
{
//do here
}
尝试:
尝试:
在您的代码变量中,
$q
在if条件之外没有可访问的范围
$q="";
因此,您需要在if条件之前定义它。在if条件上方添加以下行
$q="";
在while循环中使用以下内容:
if(!empty($q)) {
while($res=mysql_fetch_array($q)){
-----------
your code
---------------
}
}
在您的代码变量中,
$q
在if条件之外没有可访问的范围
$q="";
因此,您需要在if条件之前定义它。在if条件上方添加以下行
$q="";
在while循环中使用以下内容:
if(!empty($q)) {
while($res=mysql_fetch_array($q)){
-----------
your code
---------------
}
}
修复查询失败的问题。使用$q=mysql\u query($query)或die(mysql\u error());你能演示<代码> $q>代码>吗?你还应该将mysql查询转换为mySQLI,也可以考虑使用<代码> PDO< /代码>,特别是准备好的语句,这有助于防止SQL注入。从v5.5开始,不推荐使用
mysql\u*
函数系列:修复您的查询,因为它失败了。使用$q=mysql\u query($query)或die(mysql\u error());你能演示<代码> $q>代码>吗?你还应该将mysql查询转换为mySQLI,也可以考虑使用<代码> PDO< /代码>,特别是准备好的语句,这有助于防止SQL注入。mysql.*
函数系列从v5.5开始就被弃用了:对不起,我忘了发布代码,但现在可以了。对不起,我忘了发布代码,但现在可以了。你的意思可能是(!empty($q)&&$res=mysql\u fetch\u array($q)){是的,它非常有效,谢谢MariyoJ2D8T:为什么你认为在这个解决方案中&&&比和更好?你可能是说,(!empty($q)&&&$res=mysql\u fetch_array($q)){是的,它非常有效,谢谢MariyoJ2D8T:为什么你认为&&比和在这个解决方案中更好?