-2
<?php
    include('connection/connection.php');

    $uname=$_POST['uname'];
    $password=$_POST['password'];

    $sql=mysql_query("SELECT * FROM elemschool_admin WHERE admin_UName='$uname' AND admin_pass='$password'");
    $sql1=mysql_query("SELECT * FROM elemschool_faculty WHERE facultyID='$uname' AND faculty_password='$password'");
    $row=mysql_fetch_assoc($sql1);

    $cout=mysql_num_rows($sql);
    $cout1=mysql_num_rows($sql1);

    if($cout>0){
        $_SESSION['id']=$uname;
        header("location: modules/admin/index.php");
    }
    else{
        ?>
        <script>
            alert("Wrong Input!");
            window.location="index.php";
        </script>
        <?php
    }
?>  

I have received the error:

warning:mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in

SnareChops
  • 12,721
  • 9
  • 68
  • 90
  • Many things can be causing this problem. Perhaps your POST variables are empty, perhaps they need to be escaped... – Phiter Jan 26 '16 at 01:37

2 Answers2

0
  1. There is most likely an error in the sql query due to the mysql_fetch_assoc returning a bool (Most likely false e.g. failed query). Use the mysql_error function to find the issue.

  2. mysql_* is depreciated, please switch to mysqli_*

  3. Escape all of your input using prepared queries in mysqli or at least using escape_string to avoid SQL injection.

Matt
  • 2,833
  • 1
  • 12
  • 27
0

NOTE The mysql_ functions are deprecated and will be removed with the upcoming php version 7.

Check $result before passing it to mysql_fetch_array. You'll find that it's false because the query failed. See the mysql_query documentation for possible return values and suggestions for how to deal with them.

Refer This example:

$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '$username'");

if($result === FALSE) { 
    die(mysql_error()); // TODO: better error handling
}

while($row = mysql_fetch_array($result))
{
    echo $row['FirstName'];
}
Amitesh Kumar
  • 2,983
  • 23
  • 41