YourSurrogateGod
November 28th, 2004, 06:15 PM
Here's what I'm trying to do. I want to be able for the user to log into a webpage. I would like to get the username and password, compare them to existing ones in the database and then move that person along to the main web page, otherwise they will get an echo saying that they've screwed up. Also, once the login was succesful, 2 cookies get set so that they can be use later on in the webpage. I'm pretty confident that I've screwed this up (setcookie is supposed to go before <html> :rolleyes: ), any ideas on how I can get at what I'm trying to accomplish? How would I set a cookie after processing a specific form?
Thanks.<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>$Title</title>
</head>
<!-- Background color. -->
<body bgcolor="#FFFFFF" text="#000000">
<!-- The central title. -->
<p align="center"><font size="6">$Title</font></p>
<!-- For a new user. -->
<p align="center"><a href="newuser.php">I'm a New User</a></p>
<!-- Will indicate what action needs to be taken. -->
<form action="main.php" method="POST" name="LoginForm">
<!-- Align all of the values to the center. -->
<p align="center">Username:
<!-- Will allow the user to input his/her username. -->
<input type="text" size="50" name="Username"><br>
Password:
<!-- Will allow the user to input his/her password. -->
<input type="password" size="50" name="Password"><br>
<!-- Will display an error message if the password or username are not correct. -->
<font color="#FF0000">$ErrorMessage</font><br>
<!-- Will hold the button that will need to be pressed. -->
<input type="submit" name="Submit" value="Login"></p>
<?php
$_POST('Password');
$_POST('Username');
// Attempt to connect to the database.
$db = mysql_pconnect("localhost", "root", "255sql");
// Make sure the DB was opened.
if(!$db)
{
echo "Error: Failed to open database.";
exit;
}
mysql_select_db("cse255", $db);
if(!isset($_POST['submit']))
{
$_POST['submit'];
}
else
{
$tResult = mysql_query("SELECT FROM User_Ta WHERE UName = " .
$Username . " UPasswd = " . $Passwd .
" OR APasswd = " . $Passwd);
if(mysql_num_rows($tResult) == 0)
{
echo "ERROR: Wrong username or password.";
}
else
{
setcookie("uname", $Username);
setcookie("password", $Password);
include("main.php");
}
}
?>
</form>
</body>
</html>
Thanks.<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>$Title</title>
</head>
<!-- Background color. -->
<body bgcolor="#FFFFFF" text="#000000">
<!-- The central title. -->
<p align="center"><font size="6">$Title</font></p>
<!-- For a new user. -->
<p align="center"><a href="newuser.php">I'm a New User</a></p>
<!-- Will indicate what action needs to be taken. -->
<form action="main.php" method="POST" name="LoginForm">
<!-- Align all of the values to the center. -->
<p align="center">Username:
<!-- Will allow the user to input his/her username. -->
<input type="text" size="50" name="Username"><br>
Password:
<!-- Will allow the user to input his/her password. -->
<input type="password" size="50" name="Password"><br>
<!-- Will display an error message if the password or username are not correct. -->
<font color="#FF0000">$ErrorMessage</font><br>
<!-- Will hold the button that will need to be pressed. -->
<input type="submit" name="Submit" value="Login"></p>
<?php
$_POST('Password');
$_POST('Username');
// Attempt to connect to the database.
$db = mysql_pconnect("localhost", "root", "255sql");
// Make sure the DB was opened.
if(!$db)
{
echo "Error: Failed to open database.";
exit;
}
mysql_select_db("cse255", $db);
if(!isset($_POST['submit']))
{
$_POST['submit'];
}
else
{
$tResult = mysql_query("SELECT FROM User_Ta WHERE UName = " .
$Username . " UPasswd = " . $Passwd .
" OR APasswd = " . $Passwd);
if(mysql_num_rows($tResult) == 0)
{
echo "ERROR: Wrong username or password.";
}
else
{
setcookie("uname", $Username);
setcookie("password", $Password);
include("main.php");
}
}
?>
</form>
</body>
</html>