i am always finding this error. if you have an idea.please assist as soon as possible



 mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\validate_login.php on line 20  
 This is line with the problem as per text -editor(* $row = mysql_fetch_array($result);*)
<?php

// Grab User submitted information
$email = $_POST["users_email"];
$pass = $_POST["users_pass"];


// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected succesfully
if(! $con)
{
    die('Connection Failed'.mysql_error());
}

// Select the database to use
mysql_select_db("school",$con);

$result = mysql_query("SELECT users_email, users_pass FROM login WHERE users_email = $email");

* $row = mysql_fetch_array($result);*

if($row["users_email"]==$email && $row["users_pass"]==$pass)
    echo"You are a validated user.";
else
    echo"Sorry, your credentials are not valid, Please try again.";
?>

Put $email in single quotes since it is expected to be a string:

$result = mysql_query("SELECT users_email, users_pass FROM login WHERE users_email = '$email'");

Other issues:

  1. never trust user input since not everyone will enter email address; some nasty boys might enter a bad query instead (it is called a sql injection), therefore escape the input:

    $email = mysql_real_escape_string($_POST["users_email"]);
    $pass = mysql_real_escape_string($_POST["users_pass"]);

  2. before querying check whether user submitted the form at all and data exist:

    if(isset($_POST["users_email"])) {
    $email = mysql_real_escape_string($_POST["users_email"]);
    } else {
    // handle the error
    ...
    }

  3. use some error checking upon querying:

    $result = mysql_query("SELECT users_email, users_pass FROM login WHERE users_email = $email") or die('ERROR');

  4. avoid mysql extension, move to mysqli or PDO as soon as you can.

thanks alot broj1.
it worked

You are welcome. If this is it please mark it as solved. Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.