Hi,
I have recently installed php5 and mysql 4.1 and am following a tutorial by video from http://www.vtc.com and have come upon a problem.
I have a script that allows a user to enter a username and password, using the password() function. Then the php script connects to my mysql database and never accepts the login unless I comment out the password argument in the mysql query.
Having checked the database itself, and entered in new usernames and passwords, i still get the same result. Below is the script I am using...
<? session_start() ?>
<HTML>
<HEAD>
<TITLE>Login</TITLE>
</HEAD>
<BODY>
<H2>Login</H2>
<?
// keep hyperlinks in a string variable
$links = "<A HREF='main.php'>Click here to proceed to the main page</A><BR><BR><A HREF='logout.php'>Click here to log out.</A>";
// check to see if details have been passed to the script by the form
if ($user && $pass) {
// if already logged in *as this user*, let them know, and show them the links.
// .. of course, if they are logged in as someone else, let them log in as a different user
if ($logged_in_user == $user) {
echo $user.", you are already logged in.<BR><BR>";
echo $links;
exit;
}
// connect to database and select 'userlist' database
$db = mysql_connect("localhost","username","password");
mysql_select_db("userlist", $db);
// check input variables against database
$result = mysql_query("SELECT * FROM users WHERE name= '".$user."' AND password = PASSWORD('".$pass."')");
// in case of an error, throw up an error message and exit
if (!$result) {
echo "Sorry, there has been a technical hitch. We cannot enter your details.";
exit;
}
// greet valid user and show links
if (mysql_num_rows($result) > 0) {
$logged_in_user = $user;
session_register("logged_in_user");
echo "Welcome, ".$logged_in_user.". <BR><BR>";
echo $links;
exit;
// on invalid login, show user HTML form to login again
} else {
echo "Invalid login. Please try again.<BR><BR>";
}
// in case user only fills in one field, show error message and HTML form ..
} else if ($user || $pass) {
echo "Please fill in both fields.<BR><BR>";
}
?>
<FORM METHOD=POST ACTION="login.php">
Your username:
<INPUT NAME="user" TYPE=TEXT MAXLENGTH=20 SIZE=20>
<BR>
Your password:
<INPUT NAME="pass" TYPE=PASSWORD MAXLENGTH=30 SIZE=30>
<BR>
<INPUT TYPE=SUBMIT VALUE="Login">
</FORM>
</BODY>
</HTML>
I am guessing I haven't set something right in either the php.ini file or the my.ini file. This script works perfectly on the video.
Can someone please help?
Cheers,
Nick. 🙁