如何解决此PHP警告?

时间:2010-05-21 22:18:54

标签: php warnings

我在代码中收到此警告:

  

警告:mysql_fetch_array()期望   参数1是资源,字符串   给定的   C:\ xampp \ htdocs \ Join.php on   第69行

但我无法准确确定问题所在。 你能帮我看一下这段代码中的错误:

<?php 

   51. include("connect.php");

   53. $email = mysql_query("select MemberEmail from members where MemberID= '$id' ");
   54. while ($row = mysql_fetch_array($email))
   55.  {   

   57.  $memEmail=$row['MemberEmail'];

   }


  62.  $sql = mysql_query("select * from ninvite where recieverMemberEmail ='$memEmail'  and viwed= '0' order by  RoomID desc");

  64.  $num =mysql_num_rows($sql);


  67.  if ($sql and $num >0 )
      {
  69.   while($row=mysql_fetch_array($sql))
       {
  71.   $sender=$row['SenderMemberID'];

  73.   $room=$row['RoomID'];



  77.  $sql2 =mysql_query("select MemberName from members where MemberID ='$sender'  ");
  78.  $sql1 =mysql_query("select RoomName,RoomLogo from rooms where RoomID ='$room' ");
  79.  while($row=mysql_fetch_array($sql2))
    {
        $mem =$row['MemberName'];
    }

  84.   while($rows=mysql_fetch_array($sql1))
    {   
        $Ro =$rows['RoomName'];
        $logo = $rows['RoomLogo'];
     }
  89.  ?>

<form action="" method="post">
    <table align="center">
        <tr>


            <td colspan="3">
    <input type="hidden" name="invite_id" value="<?php echo $room; ?>" />
   <label> 
   </label> <br/>
    <label> <?php echo "   
you have  invite from  $mem to join  $Ro "; ?> </label>  

    <br/>
     <label>accept</label>
    <input name="radio1" type="radio" value="accpet"  />
     <label>reject</label>
    <input name="radio1" type="radio" value="Reject"  /><br/><br/>
  <input  align="" type="submit" name="submit" value="submit" />
      </td>

             <td colspan="3">
    <?php echo "<p align=''><img width='90' height='90' src='" .$logo. "' alt='' /></p>"; ?>
            </td>
        </tr>
    </table>
</form>




<?php



if (isset ($_POST['submit']))
    {
// connect to the mysql server
include ("connect.php");

// insert the data
$button=$_POST['radio1'];
$room = $_POST['invite_id'];




if ($button=='Reject' )
{

mysql_query("INSERT INTO joinroom (MemberID, RoomID) VALUES ('$id', '$room')");

$sql = ("DELETE FROM ninvite  WHERE RoomID = '$room'");
$R=mysql_query($sql);
// print a success message
echo " <center> success join this team <br></center>"; }

else 
{

echo "<center> reject this invite /center> ";
$sql = ("DELETE FROM ninvite WHERE RoomID = '$room' " );
$R=mysql_query($sql);
}

echo "  <meta http-equiv=\"refresh\" content=\"3;URL=Join2.php\">";

}  }  }

?>

非常感谢!

5 个答案:

答案 0 :(得分:2)

不应viwedviewed

select *
from ninvite
where recieverMemberEmail = '$memEmail'
and viewed = '0'
order by RoomID desc

答案 1 :(得分:0)

我很惊讶你没有在第64行(也期望资源)上收到错误。第62行的SQL在数据库中生成错误。暂时将其更改为:

$sql = mysql_query("select * from ninvite where recieverMemberEmail ='$memEmail'  and viwed= '0' order by  RoomID desc") or die(mysql_error());

并检查打印的错误消息。

答案 2 :(得分:0)

$sql = mysql_query("select * from ninvite where recieverMemberEmail ='$memEmail'  and viwed= '0' order by  RoomID desc");

我认为一定是这样的:

$sql = mysql_query("select * from ninvite where recieverMemberEmail ='".$memEmail."'  and viwed= '0' order by  RoomID desc");

答案 3 :(得分:0)

第67行应该是:

if ($sql && $num >0 )

不是

if ($sql and $num >0 )

答案 4 :(得分:0)

你的问题在线:

$sql = ("DELETE FROM ninvite  WHERE RoomID = '$room'");

因为你没有关闭while循环的括号,所以你打开了第70行。