开发者

How to resolve this PHP warning?

I get this warning in my code:

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\Join.php on line 69

But I cannot identify exactly where the problem is. Can you help me spot the error in this code:

<?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  ali开发者_运维技巧gn="" 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\">";

}  }  }

?>

Thanks a lot!


Shouldn't viwed be viewed?

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


I'm surprised you're not getting an error on line 64 (which also expects a resource). The SQL on line 62 is generating an error in the database. Temporarily change it to:

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

and inspect the printed error message.


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

I think it must be like this:

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


line 67 should be :

if ($sql && $num >0 )

not

if ($sql and $num >0 )


Your problem is at line:

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

because you didn't close the brace of the while loop you opened line 70.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜