php authentication
Posted: Thu Jul 25, 2002 2:38 pm
somebody please help me, i beg of you.
i am not very versed in php. i'm trying so hard and want to learn.
i have spent weeks on trying to just do a password protection.
i went to a tutorial for user authentication at the following:
http://www.phpdeveloper.org/view_tut.php?id=41
i have a database and successfully created a table and populated it with a name and password.
i cannot get the page to work. what am i doing wrong?
this is the code i wrote:
opening with the php tag (leaving out of this post), then
print "
//now the html and body tags (leaving out of this post) and then
<form method=post action=$PHP_SELF>
<table cellpadding=2 cellspacing=0 border=0>
<td>Username:</td><td><input type=\"text\" name=\"username\" size=10></td><tr>
<td>Password:</td><td><input type=\"password\" name="password" size=10></td><tr>
<td> </td><td><input type=\"submit\" name=\"submit\" value=\"Log In\"></td>
</table></form>
//closing body and html tags (leaving out of this post)
";
if ($submit) {
// Include config file contains database info
include("common.php");
// Connect to database
$link = dbConnect() or die ("can't connect");
mysql_select_db($dbName) or die ("cant change");
$result=mysql_query("select * from User where name='$username'",$link) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
if ($row["password"]==$password) {
printf("Successfully Logged In!<a href=\\"default.php?\\"'>Click Here</a>");
}
}
}
//closing php tag (leaving out of this post)
if anyone can help, it would be so appreciated.
thanks in advance for any assistance.
josephine