Greetings and thank you for the looksee.
On my login form, I'm expecting one of two results. either to be logged in, or else
echo 'That information is incorrect, try again. I keep recieving the error message:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/49/7706749/html/storeadmin/admin_login.php on line 22
AND ''That information is incorrect, try again Click Here"
My understanding of the message is that a result for my query is not being found.
I just can't figure out why.
I have checked for spelling, rechecked my connection file, changed/ added other usernames & passwords to the admin table, Plus countless other work arounds I tried in desperation. The only one with ANY result was removing "line 22:$existCount = mysql_num_rows($sql);" completely, which created other session issues. here is the code, and let me appologise in advance if I could have done somethin to make this easier to read. Here is the code:😕
admin_login
<?php
include "../storescripts/connect_to_mysql.php";
session_start();
if (isset($_SESSION["manager"])) {
header("location:storeadmin/index.php");
exit();
}
?>
<?php
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters
// Connect to the MySQL database
$sql = mysql_query("SELECT id FROM admin WHERE id='$managerID' AND
username='$manager' AND
password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql);
// count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $manager;
$_SESSION["password"] = $password;
header("location:index.php");
exit();
} else {
echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Log In </title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
<?php include_once("../template_header.php");?>
<div id="pageContent"><br />
<div align="left" style="margin-left:24px;">
<h2>Please Log In To Manage the Store</h2>
<form id="form1" name="form1" method="post" action="admin_login.php">
User Name:<br />
<input name="username" type="text" id="username" size="40" />
<br /><br />
Password:<br />
<input name="password" type="password" id="password" size="40" />
<br />
<br />
<br />
<input type="submit" name="button" id="button" value="Log In" />
</form>
<p> </p>
</div>
<br />
<br />
<br />
</div>
<?php include_once("../template_footer.php");?>
</div>
</body>
</html>