dsirr48088 2013-11-15 03:12
浏览 27

如何删除这个mysql警告[重复]

I need the help, any one help me to remove this Warning message, here the code.

 <?php
     $fname="fname";
     $exam_name="exam_name";
     $date="date";
     $class="class";
     $query="query";
     $query2="query2";
     $database=("mcl");
     mysql_connect("localhost","root","mcl");
     @mysql_select_db(mcl) or die( "Unable to select database");


        if(isset($_REQUEST['submit'])){
           $fname=$_POST['fname'];
        $date=$_POST['date'];
         $exam_name=$_POST['exam_name'];
         $class=$_POST['class'];
            $sql=" SELECT * FROM stdreg_exam WHERE fname like '%".$fname."%' AND  
            exam_name like '%".$exam_name."%'AND class like '%".$class."%' AND date  
                like '%".$date."%'" or die(mysql_error());

  $sql2 
    ="SELECT(mathematics+english+kiswahili+geograph+civics+french+religion+
      pds+vskill+ict+science+history)/12 FROM stdreg_exam( as Average, (SELECT    
       (mathematics+english+kiswahili+geograph+civics+french+religion+
      pds+vskill+ict+science+history) FROM stdreg_exam( as Total WHERE fname like  
      '%".$fname."%' AND exam_name like '%".$exam_name."%'AND class like  
        '%".$class."%' AND date like '%".$date."%'" or die(mysql_error());



     $q=mysql_query($sql);
   $q=mysql_query($sql2);


        }
   else{
           $sql="SELECT * FROM stdreg_exam";
            $q=mysql_query($sql);
              }
                ?>
     <form method="post">
              <table width="500" border="0">
             <tr>
            <td>Student name</td>
            <td><input type="text" name="fname" value="<?php echo $fname;?>" /></td>
            <td>Exam name</td>
            <td><input type="text" name="exam_name" value="<?php echo $exam_name;?>"  
              /></td>
            <td>Class</td>
            <td><input type="text" width="10" name="class" value="<?php echo  
            $class;?>" /></td>

       <td>Date</td>
        <td><input type="date" name="date" value="<?php echo $date;?>" /></td>

        <td><input type="submit" name="submit" value="Search" /></td>
        </tr>
           </table>
           <br />
             </form>
           <table>
      <h4><?php echo $exam_name;?>&nbsp;examinaton result of&nbsp;<?php echo    
        $fname;?>         
       &nbsp;held on&nbsp;<?php echo $date;?></h4><hr> 
          <table width="1110" border="0" cellpadding="2" cellspacing="1" >
       <tr>
     <td bgcolor="#CCCCCC" width="2000">Student name</td>
     <td bgcolor="#CCCCCC" width="10">Mathematics</td>
      <td bgcolor="#CCCCCC" width="10">English</td>
       <td bgcolor="#CCCCCC" width="10">Kiswahili</td>
        <td bgcolor="#CCCCCC" width="10">Geograph</td>
        <td bgcolor="#CCCCCC" width="10">Civics</td>
          <td bgcolor="#CCCCCC" width="10">French</td>
          <td bgcolor="#CCCCCC" width="10">Religion</td>
            <td bgcolor="#CCCCCC" width="10">Pds</td>
             <td bgcolor="#CCCCCC" width="10">Vskill</td>
             <td bgcolor="#CCCCCC" width="10">Ict</td>
              <td bgcolor="#CCCCCC" width="10">Science</td>
                <td bgcolor="#CCCCCC" width="10">History</td>
                 <td bgcolor="#CCCCCC" width="10">Average</td>
                  <td bgcolor="#CCCCCC" width="10">Total</td>
    <td bgcolor="#CCCCCC" width="10">Exam_name</td>
    <td bgcolor="#CCCCCC" width="1000">Class</td>
    <td bgcolor="#CCCCCC" width="1000">Date</td>
         </tr>
       <?php
            while($res=mysql_fetch_array($q)){
             ?>
           <tr>
            <td width="100"><?php echo $res['fname'];?></td>
            <td width="10"><?php echo $res['mathematics'];?>%</td>
     <td width="10"><?php echo $res['english'];?>%</td>
     <td width="10"><?php echo $res['kiswahili'];?>%</td>
     <td width="10"><?php echo $res['geograph'];?>%</td>
     <td width="10"><?php echo $res['civics'];?>%</td>
    <td width="10"><?php echo $res['french'];?>%</td>
    <td width="10"><?php echo $res['religion'];?>%</td>
    <td width="10"><?php echo $res['pds'];?>%</td>
    <td width="10"><?php echo $res['vskill'];?>%</td>
    <td width="20"><?php echo $res['ict'];?>%</td>
    <td width="10"><?php echo $res['science'];?>%</td>
    <td width="10"><?php echo $res['history'];?>%</td>
    <td width="30"><?php echo $res2['Average']; ?></td>
    <td width="30"><?php echo $res2['Total']; ?></td>
    <td width="10"><?php echo $res['exam_name'];?></td>
    <td width="30"><?php echo $res['class'];?></td>

    <td width="280" style="border-width:medium"><?php echo $res['date'];?></td>
</tr>
<?php }?>

When I run the query it give me this message (Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\db_valentine_V2\std_report_exam.php on line 322), help please.

</div>
  • 写回答

2条回答 默认 最新

  • douzhou7656 2013-11-15 03:15
    关注

    It's probably an error in your SQL. http://us2.php.net/mysql_query

    The query commands returns FALSE on some failures and that's why you're getting a boolean value. Check for

    if ($q === false)
    

    to determine if there was an error

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。