Login sql help

Hey guys im having trouble with the logging in process

im getting this error but im not sure what it is or how to fix it.

“Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /Applications/XAMPP/xamppfiles/htdocs/assign2-test/process/process-login.php on line 4”

heres the code for “precess-login.php”
[php]<?php
require “…/inc/dbconnect.php”;

  if (mysql_num_rows($result) >= 1)
{
    header("Location: ../pages/show-products.php");
}
else
{
    echo "<p>You have not entered a valid username and password.</p>";
    echo "<p><a href='../pages/login.php'>Back to login</a></p>";
}

$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];

// hash the password
//$password = hash('sha512', $password); 

$sql = "SELECT empID, password
		FROM employees
		WHERE empID = '{$empID}'
		AND password = '{$password}'";

echo $sql;
echo "<br />";
$result = mysql_query($sql);

echo "Redirect";


include "../inc/footer.php";

?> [/php]

and heres the login.php page where you actually log in
[php]<?php
require “…/inc/dbconnect.php”;

if (isset($_SESSION['empID']))

{
// the user is logged in
echo “

You are logged in, {$_SESSION[‘empID’]}!

”;
}
?>

Login

Username:
Password:
<?php include "../inc/footer.php"; ?>[/php]

the session start is in the dbconnect.php file which is required on both pages

"Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /Applications/XAMPP/xamppfiles/htdocs/assign2-test/process/process-login.php on line 4"

mysql_num_rows expects 1 parameter and null is given. the query is not being executed sucessfully.

try
[php]
$result = mysql_query($sql) or die(mysql_error());
[/php]

try to fix the error if not post here what your new error is.

after you see what your new error is, you can fix it by putting tics around password like this password.

Sponsor our Newsletter | Privacy Policy | Terms of Service