943,617 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 475
  • PHP RSS
Oct 9th, 2008
0

login error

Expand Post »
Hello pipo Iam pretty new at php.I implemented a log in page as shown below:


<?php
session_start();
include("./connect.php");

// start the session


$errorMessage = '';
if (isset($_POST['txtUsername']) && isset($_POST['txtPassword'])) {

//---------------------------------------------------------------
if (isset($_POST['submit'])) { // if form has been submitted

//check out the fields
if (isset($_POST['txtUsername']) || isset($_POST['txtPassword'])) {
// check for required values
if (empty($_POST['txtUsername'])) {
die("ERROR: Please enter the username!");
}
if (empty($_POST['txtPassword'])) {
die("ERROR: Please enter password!");
}
}
}
//---------------------------------------------------------------
$result = mysql_query("SELECT Username, Password FROM members WHERE Username ='$_POST[txtUsername]' AND Password = '$_POST[txtPassword]'",$dbc);

// check if the specified username and password has been found

if (mysql_affected_rows() ==1) {

// set the session
$_SESSION['logged_in'] = true;

// after login we move to the main page

$loginpage="enterlottery.html";
?>
<HEAD>
<script type="text/javascript">
<!--
location.replace("<?php echo $loginpage; ?>?sid=<?php echo strip_tags($sid); ?>");
//-->
</script>
</HEAD>
<?php


}
else
{
$errorMessage = 'Sorry, wrong username and password,please try again!!!';
}
}

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

and am getting the following error:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\lottery\memberlogin.php:2) in C:\wamp\www\lottery\memberlogin.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\lottery\memberlogin.php:2) in C:\wamp\www\lottery\memberlogin.php on line 3

please help
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
65!sesa is offline Offline
1 posts
since Oct 2008
Oct 9th, 2008
1

Re: login error

seems to me as if you have an empty line at the beginning of your code. Make sure that the php-tag "<?" starts directly at the beginning of your file, that all code that you include before don't echo anything and no echo or print is used in your file before your start your session. In this case it really seems to be a line break at the beginning of the file.
Reputation Points: 56
Solved Threads: 29
Posting Whiz in Training
sDJh is online now Online
255 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP - MySQL Dilemna
Next Thread in PHP Forum Timeline: Unable to preform queries within one button





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC