PHP LogIn Error
Posted: Wed Sep 09, 2009 8:54 pm
I just built a login page for my web site. I have looked through my code about 10 million times or so it seems and still cannot get it fixed. Whenever I click the submit button it just brings me back to the login page. Can someone please look over my code and see if you see anything wrong? Thanks!
<!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>Untitled Document</title>
</head>
<body>
<?php
$con = mysql_connect("localhost", "tutorial", "**************");
mysql_select_db("tutorial");
$usernamefield = $_POST['username'];
$passwordfield = $_POST['password'];
$logincheck = mysql_query("SELECT * FROM logintable WHERE user='$usernamefield' AND pass='$passwordfield'");
$rows = mysql_fetch_array($logincheck);
if ($rows != "") {
echo "Welcome to the members area";
}
else {
?>
<form id="form1" name="form1" method="post" action="">
<p>
<label>
User Name:
<input type="text" name="username" id="username" />
</label>
</p>
<p>Password:
<label>
<input type="text" name="password" id="password" />
</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>
</body>
</html>
<!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>Untitled Document</title>
</head>
<body>
<?php
$con = mysql_connect("localhost", "tutorial", "**************");
mysql_select_db("tutorial");
$usernamefield = $_POST['username'];
$passwordfield = $_POST['password'];
$logincheck = mysql_query("SELECT * FROM logintable WHERE user='$usernamefield' AND pass='$passwordfield'");
$rows = mysql_fetch_array($logincheck);
if ($rows != "") {
echo "Welcome to the members area";
}
else {
?>
<form id="form1" name="form1" method="post" action="">
<p>
<label>
User Name:
<input type="text" name="username" id="username" />
</label>
</p>
<p>Password:
<label>
<input type="text" name="password" id="password" />
</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>
</body>
</html>
[/img]