I am attempting to create a login script. It doesn't seem to be working and I thought that someone might be able to point out what I' doing wrong.
What I mean by not working is that it will not log me in.
Here's my code:
<?php
// Assume user is not authenticated
$auth = false;
if (isset($username) && isset($userpass)) {
// Connect to MySQL
$linkID = mysql_connect("localhost", $dbUsername, $dbPassword) or die ("I cannot connect to the database.");
// Select database on MySQL server
mysql_select_db($databaseName) or die ("I cannot connect select msworksh_reference." . mysql_error($linkID));
// Formulate the query
$sql = "SELECT * FROM users $tableName WHERE Username = '$username' AND Userpass = '$userpass'";
// Execute the query and put results in $resultID
$resultID = mysql_query($sql, $linkID) or die ("Unable to execute query. " . mysql_error($linkID));
// Get number of rows in $resultID
$num = mysql_numrows($resultID);
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
} // END IF
} // END IF
if ( !$auth ) {
?>
<form name="" action="<?php echo $PHP_SELF; ?>" method="post">
username: <input type="text" name="username" /><br />
userpass: <input type="text" name="userpass" /><br />
<input type="submit" />
</form>
<?php
} else {
echo '<P>Authorization Successful.</P>';
} // END IF
?>
Here's my table information i(mySQL:
CREATE TABLE users (
UserKey int(8) NOT NULL auto_increment,
UserFirstName varchar(30) NOT NULL default '',
UserLastName varchar(30) NOT NULL default '',
Username varchar(15) NOT NULL default '',
Userpass varchar(15) NOT NULL default '',
PostDate timestamp(14) NOT NULL,
PRIMARY KEY (UserKey)
) TYPE=MyISAM AUTO_INCREMENT=4 ;
Here's the user infor that I'm testing with:
INSERT INTO users VALUES (3, 'firstname', 'lastname', 'username', 'password', 20040128154358);
Environment stats:
PHP 4.3.3
MySQL 3.23.56
Thanks in Advance,
Mark