mysql query

0 athuman said · February 22, 2015
when i compile my code below i met with the warning below.
"
Warning: mysql_fetch_array() expects parameter 1 to be resource, object given inC:\xampp\htdocs\design\mailinbox.php on line 33" 

                .......please help me....

<?php

include("header.php");
include("dbconnection.php");
if(isset($_GET["mailid"]))
{
mysqli_query("DELETE FROM mail where mailid='$_GET[mailid]'");
$recres = "Mail deleted Successfully...";
}
$result = mysqli_query($con,"SELECT * FROM mail where reciverid='$_SESSION[admin]'");
?>
    
     <div id="templatemo_main">
  <div align="center"><span class="main_top"></span> 
    
  </div>
  <div align="center"></div>
  <div id="templatemo_content">
      <h2 align="center">INBOX</h2>
            <?php
            global $recres;
             echo $recres; ?>
         <table width="600" border="1">
    
             
              <?php
echo " <tr>";
                echo " <th scope='col' width='45' >Delete</th>";
                echo " <th scope='col'>SENDER</th>";
                echo " <th scope='col'>SUBJECT</th>";
                echo " <th scope='col'>TIME</th>";
                echo " </tr>";

 33    *******this line  has error*****      while($row = mysql_fetch_array($result))

  {
    echo " <tr>";
                echo " <th scope='col'><a href='mailinbox.php?mailid=$row[mailid]'>Delete</a></th>";
                echo " <th scope='col'>$row[senderid]</th>";
                echo " <th scope='col'>$row[subject]</th>";
                echo " <th scope='col'>$row[mdatetime]</th>";
                echo " </tr>";
  }
?>           
      </table>
         </form>
        <?php

?>

Post a Reply

Replies

Oldest  Newest  Rating
+1 Michael Chimezie · February 28, 2015
First you are kinda mixing mysqli with mysql. You should quote your session variable like this $_SESSION['admin'] and NOT $_SESSION[admin]
+1 Mohamad Mirohamadi · February 28, 2015
replace line 9 with this:
$result = mysqli_query($con,"SELECT * FROM mail where reciverid='{$_SESSION['admin']}'");
0 Jay Deshaun · February 28, 2015
I would suggest using $_REQUEST as it gets the query from both _GET or _POST.
Try this:
<?php
requlre("header.php");
require("dbconnection.php");
if(isset($_REQUEST["mailid"])){
mysqli_query("DELETE FROM mail where mailid='$_GET[mailid]'");
$recres = "Mail deleted Successfully...";
}
$result = mysqli_query($con,"SELECT * FROM mail where reciverid='{$_SESSION['admin']}'");
?>

<div id="templatemo_main">
<div align="center"><span class="main_top"></span>
</div>
<div align="center"></div>
<div id="templatemo_content">
<h2 align="center">INBOX</h2>
<?php
global $recres;
echo $recres;
?>

<table width="600" border="1">

<?php
echo ' <tr>'. PHP_EOL .' <th scope='col' width='45' >Delete</th>'. PHP_EOL .' <th scope='col'>SENDER</th>'. PHP_EOL .
' <th scope='col'>SUBJECT</th>'. PHP_EOL .' <th scope='col'>TIME</th>'. PHP_EOL .' </tr>';
while($row = mysql_fetch_array($result)){
echo ' <tr>'. PHP_EOL .' <th scope='col'><a href='mailinbox.php?mailid=$row[mailid]'>Delete</a></th>'. PHP_EOL .
' <th scope='col'>$row[senderid]</th>'. PHP_EOL .' <th scope='col'>$row[subject]</th>'. PHP_EOL .' <th scope='col'>$row[mdatetime]</th>'. PHP_EOL .
' </tr>';
}
?>
</table>
</form>
0 Sachin Kumar · February 22, 2015
Check $result before passing it to mysql_fetch_array(). You'll find that it's false because the query failed.
$_GET["mailid"]
$_SESSION["admin"]
  • 1

PHP

103,726 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators