Alright, first things first, a little explanation of what's going on. Currently, I am using a login php script, to authenticate intranet logins. I also created a database with MySQL called auth and a table within auth called userinfo by using the following statement :
--------------------------------------------------------------------------------
create table userinfo (username varchar(12), password varchar(12));
--------------------------------------------------------------------------------
Then, I inserted 2 login/password entries, by using the following statement:
--------------------------------------------------------------------------------
mysql> INSERT INTO username VALUES ('joe','joe');
mysql> INSERT INTO username VALUES ('henry','henry');
--------------------------------------------------------------------------------
then, I use select * from userinfo, and it provides me with a table like this:
-------------------------------------------------------
+--------------+------------+
| username | password |
+--------------+------------+
| joe | joe |
| henry | henry |
+----------+----------------+
--------------------------------------------------------
so, I KNOW the table is working correctly, as I can now display field values in my database....
So, I build my php script, and html files. Here is the code I am using ( I have went ahead and changed the values to what I have on my system at home... ) :
THIS IS FOR LOGIN.PHP
Code: Select all
<?
# Login Code Written by Matt Slavin
# Email Me At neophite17@hotmail.com for questions or comments.
if((!$username) | (!$password))
{
print ("Please Enter In THe Correct Name");
}
mysql_connect("localhost","bob","bob") or die("Could not connect to MySQL!!");
mysql_select_db("auth") or die("Could not connect to auth Database!");
$sql = "select * from userinfo where password=$password and username=$username";
$result = mysql_query($sql) or die("Could not query table userinfo!!");
$num = mysql_numrows($result);
# If Login Is Okay Do What You Want TO DO to Them
if ($num > "1")
{
print ("Logged in okay");
#Or you can send them somwhere nice like hawaii
header("Location: http://localhost/bob/success.htm");
exit;
# or even fetch feild about them or save sessions
session_start();
session_register(username);
}
# And we must a have a default error message if login fails
if ($num == "0")
{
print ("Sorry Bub You Need Some Manners In Password");
}
?>THIS IS FOR INDEX.HTM ( courtesy of mr_griff )
Code: Select all
<html>
<head>
<title>Please Login</title>
</head>
<body>
<form action="login.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="buttonSelection" value="Login">
</form>
</body>
</html>So, I run the code, and try to login. I type joe, joe for the username/password, and instead of seeing the success.htm, I get
Please Enter In THe Correct Name
as if I entered the wrong username/password.
So, I redid the code, and put some more debugg scripts in there that would tell me what was going on, if it's a problem with the code, or connection to the sql database.
So, I changed the following around:
Code: Select all
mysql_connect("localhost","bob","bob") or die("Could not connect to MySQL!!");
Print "Connected to MySQL successfully...";
Print "<br>";
Print "Attempting to connect to MySQL Database";
Print "<br>";
mysql_select_db("auth") or die("Could not connect to auth Database!");
Print "Connected to auth Database successfully...";
Print "<br>";
Print "Attempting to connect to Table....";
Print "<br>";
$sql = "select * from userinfo where password=$password and username=$username";
$result = mysql_query($sql) or die("Could not query table userinfo!!");
Print "Connected to userinfo Table successfully... Checking Login/Password";
Print "<br>";
$num = mysql_numrows($result);The result in this, is it displays that I connect to MySQL successfully, and then to the database successfully, but it stops there. It doesn't give me a message saying that I did not connect to the table successfully, NOR does it tell me that it queried the table successfully...
So, What I belive, is there is something wrong with my php script in how it is connecting to the table, or I don't have something setup correctly...
Hope someone can straighten this out for me
heh, thanks in advance