<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<?php
// connection to MySQL server
mysql_connect('localhost','root','');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password']; 
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "admin.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');

  $errors = array();

     if(empty($_POST['username'])) {
     $errors[] = 'You think your father going to fill up the USERNAME for you?';
     }  
     if(empty($_POST['password'])) {
        $errors[] = 'Where is the PASSWORD you asshole!';
     }  
    if (empty($errors)) {

  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS_query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  $LoginRS = mysql_query($LoginRS_query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);

  if ($loginFoundUser) {

    setcookie ('username', $loginFoundUser[0]);
    setcookie ('password', $loginFoundUser[1]);

    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
        if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
            $url = substr ($url, 0, -1);
            }
        $url .= '/validated.php';

        header("Location: $url");
        exit();

        } 
        else {
            $errors[] = 'The email address and password entered do not match those on file.';
            $errors[] = mysql_error() . '<br /><br />Query: ' . $query;
        }
    }
}

    mysql_close();

?>  

<html>
<head>
    <title>Cycle Tracks Portal - Administrator's Page</title>
        <style type="text/css" media="all">@import "images/style.css";
</style>
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<div class="content">
    <div class="topmenu">
        <div class="date_"><? echo date('l dS \of F Y'); ?></div>
    </div>

    <div id="submenu">
    </div>

    <div class="cycle">
        <div class="title" style="text-align: center; width: 179px">
            <sup>
            <span class="copynresv">©</span></sup>CYCLE TRACKS<sup><span class="copynresv">®</span></sup></div>
        <div class="slogan" style="width: 223px; height: 11px">&quot;We are ONE of the BEST and NOT like the REST!</div>
    </div>

    <div class="nav">
        <ul>
            <li><a href="#">HOME</a> | </li> 
            <li><a href="#">INSTRUCTIONS</a> | </li>
            <li><a href="#">FIND</a> | </li> 
            <li><a href="#">DISPLAY</a> | </li>
            <li><a href="#">ADMIN</a> | </li>
            <li><a href="#">CREDITS</a></li>
        </ul>
    </div>
    <br>
    </br>
    <table style="width: 764px; height: 141px;"align="center" cellspacing="1">
        <tr>
            <td>
            <form name="adminInput" action="admin.php" method="post" style="height: 99px">
            <table style="width: 284px; height: 56px" align="center">
                <tr>
                    <td style="width: 189px; height: 21px;" class="uspstyle">Username</td>
                    <td style="width: 191px; height: 21px;">
                        <input type="text" name="username" size="30"/>
                    </td>
                </tr>
                <tr>
                    <td style="width: 189px; height: 21px;" class="uspstyle">Password</td>
                    <td style="width: 191px; height: 21px;">
                    <input type="password" name="password" size="30"/>
                    </td>
                </tr>
                <tr>
                    <td style="width: 189px; height: 36px;" class="uspstyle"></td>
                    <td style="width: 191px; height: 36px;">
                    <table style="width: 100%">
                        <tr>
                            <td style="width: 89px">
                            <input type="submit" name="submit" value="Login" class="uspstyle2" style="height: 23px; width: 88px"/></td>
                            <td style="width: 89px">
                            <input type="reset" name="reset" value="Clear" class="uspstyle2" style="height: 23px; width: 88px"/></td>
                        </tr>
                    </table>
                    </td>
                </tr>
            </table>
            </form>
                <?php
                if (!empty($errors)) { // Print any error messages.
                    echo '<h1 class="errorLog1">Error!</h1>
                    <p class="errorLog2">The following error(s) occurred:<br />';
                    foreach ($errors as $msg) { // Print each error.
                        echo " - $msg<br />\n";
                    }
                    echo '</p><p class="errorLog3">Please try again.</p>';
                }
                ?>
            </td>
        </tr>
    </table>
    <div class="footer">
        <div class="padding">
            &copy; Copyright Cycle Tracks <span>®</span></div>
    </div>


</div>

</body>
</html>

<?php
?>

errors:
Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\cycle\admin.php:3) in E:\xampp\htdocs\cycle\admin.php on line 37

Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\cycle\admin.php:3) in E:\xampp\htdocs\cycle\admin.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\cycle\admin.php:3) in E:\xampp\htdocs\cycle\admin.php on line 46

Please help.

Edited 3 Years Ago by Dani: Formatting fixed

You can't send any data before you try to send headers. All that text above the php tags must be moved below.

Also you have selected the same db twice, almost right after each other, not related to your error, but it saves one query ;)

This is admin.php

<?php
// connection to MySQL server
mysql_connect('localhost','root','');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password']; 
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "admin.php";
  $MM_redirecttoReferrer = true;
  
  $errors = array();
  
	 if(empty($_POST['username'])) {
  	 $errors[] = 'You think your father going to fill up the USERNAME for you?';
	 }	
	 if(empty($_POST['password'])) {
		$errors[] = 'Where is the PASSWORD you asshole!';
	 }	
	if (empty($errors)) {
	
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS_query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  $LoginRS = mysql_query($LoginRS_query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  
  if ($loginFoundUser) {
  
    setcookie ('username', $loginFoundUser[0]);
	setcookie ('password', $loginFoundUser[1]);
	
	$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
			$url = substr ($url, 0, -1);
			}
		$url .= '/validated.php';
		header("Location: $url");	
		//echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";
		exit();
				
		} 
		else {
			echo "<script type='text/javascript'>location.href='$MM_redirectLoginFailed';</script>";
		}
	}
}
		
	mysql_close();

?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">	
	
<html>
<head>
	<title>Cycle Tracks Portal - Administrator's Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<div class="content">
	<div class="topmenu">
		<div class="date_"><? echo date('l dS \of F Y'); ?></div>
	</div>
	
	<div id="submenu">
	</div>
		
	<div class="cycle">
		<div class="title" style="text-align: center; width: 179px">
			<sup>
			<span class="copynresv">©</span></sup>CYCLE TRACKS<sup><span class="copynresv">®</span></sup></div>
		<div class="slogan" style="width: 223px; height: 11px">&quot;We are ONE of the BEST and NOT like the REST!</div>
	</div>
	
	<div class="nav">
		<ul>
			<li><a href="#">HOME</a> | </li> 
			<li><a href="#">INSTRUCTIONS</a> | </li>
			<li><a href="#">FIND</a> | </li> 
			<li><a href="#">DISPLAY</a> | </li>
			<li><a href="#">ADMIN</a> | </li>
			<li><a href="#">CREDITS</a></li>
		</ul>
	</div>
	<br>
	</br>
	<table style="width: 764px; height: 141px;"align="center" cellspacing="1">
		<tr>
			<td>
			<form name="adminInput" action="admin.php" method="post" style="height: 99px">
			<table style="width: 284px; height: 56px" align="center">
				<tr>
					<td style="width: 189px; height: 21px;" class="uspstyle">Username</td>
					<td style="width: 191px; height: 21px;">
						<input type="text" name="username" size="30"/>
					</td>
				</tr>
				<tr>
					<td style="width: 189px; height: 21px;" class="uspstyle">Password</td>
					<td style="width: 191px; height: 21px;">
					<input type="password" name="password" size="30"/>
					</td>
				</tr>
				<tr>
					<td style="width: 189px; height: 36px;" class="uspstyle"></td>
					<td style="width: 191px; height: 36px;">
					<table style="width: 100%">
						<tr>
							<td style="width: 89px">
							<input type="submit" name="submit" value="Login" class="uspstyle2" style="height: 23px; width: 88px"/></td>
							<td style="width: 89px">
							<input type="reset" name="reset" value="Clear" class="uspstyle2" style="height: 23px; width: 88px"/></td>
						</tr>
					</table>
					</td>
				</tr>
			</table>
			</form>
				<?php
				if (!empty($errors)) { // Print any error messages.
					echo '<h1 class="errorLog1">Error!</h1>
					<p class="errorLog2">The following error(s) occurred:<br />';
					foreach ($errors as $msg) { // Print each error.
						echo " - $msg<br />\n";
					}
					echo '</p><p class="errorLog3">Please try again.</p>';
				}
				?>
			</td>
		</tr>
	</table>
	<div class="footer">
		<div class="padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
	</div>
	
	
</div>

</body>
</html>

<?php
?>

AND
This is validated.php

<?php

if (!isset($_COOKIE['username'])) {
	//$MM_redirectLoginFailed = "admin.php";

	$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

	if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
		$url = substr ($url, 0, -1);
	}
	
	$url .= '/validated.php';
	header("Location: $url");
	//echo "<script type='text/javascript'>location.href='$MM_redirectLoginFailed';</script>";
	exit();
}

echo "<h1>Logged In!</h1>
<p>You are now logged in, {$_COOKIE['username']}!</p>
<p><br /><br /></p>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">	
	
<html>
<head>
	<title>Cycle Tracks Portal - Administrator's Page</title>
		<style type="text/css" media="all">@import "images/style.css";
		</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
	<script language="javascript">
		if(document.images) {
			imageAddBefore = new Image
			imageAddAfter = new Image
			imageAddBefore.src = "images/add_before.png"
			imageAddAfter.src = "images/add_after.png"
			imageEditBefore = new Image
			imageEditAfter = new Image
			imageEditBefore.src = "images/edit_before.png"
			imageEditAfter.src = "images/edit_after.png"
			imageDelBefore = new Image
			imageDelAfter = new Image
			imageDelBefore.src = "images/del_before.png"
			imageDelAfter.src = "images/del_after.png"
		}
	</script>
</head>

<body>
<div class="content">
	<div class="topmenu">
		<div class="date_"><? echo date('l dS \of F Y'); ?></div>
	</div>
	
	<div id="submenu">
	Validation Successful !<br />
	Administrator's Page !</div>
		
	<div class="cycle">
		<div class="title" style="text-align: center; width: 179px">
			<sup>
			<span class="copynresv">©</span></sup>CYCLE TRACKS<sup><span class="copynresv">®</span></sup></div>
		<div class="slogan" style="width: 223px; height: 11px">&quot;We are ONE of the BEST and NOT like the REST!</div>
	</div>
	
	<div class="nav">
		<ul>
			<li><a href="index.php">HOME</a> | </li> 
			<li><a href="#">INSTRUCTIONS</a> | </li>
			<li><a href="#">FIND</a> | </li> 
			<li><a href="#">DISPLAY</a> | </li>
			<li><a href="admin.php">ADMIN</a> | </li>
			<li><a href="logout.php">LOGOUT</a> | </li>
			<li><a href="#">CREDITS</a></li>
		</ul>
	</div>
	
	<table style="width: 764px; height: 141px;"align="left" cellspacing="1">
		<tr>
			<td>
				<table style="width: 100%">
					<tr>
						<td style="width: 249px" class="imgADE">
							<a href ="#" onmouseover = "document.addbut.src =imageAddAfter.src" onmouseout = "document.addbut.src =imageAddBefore.src">
								<img src = "images/add_before.png" alt="Add Cycle" name = "addbut" width="156" height="34"/>
							</a>
						</td>
						<td style="width: 248px" class="imgADE">
							<a href ="#" onmouseover = "document.editbut.src =imageEditAfter.src" onmouseout = "document.editbut.src =imageEditBefore.src">
								<img src = "images/edit_before.png" alt="Add Cycle" name = "editbut" width="156" height="34"/>
							</a>
						</td>
						<td style="width: 249px" class="imgADE">
							<a href ="#" onmouseover = "document.delbut.src =imageDelAfter.src" onmouseout = "document.delbut.src =imageDelBefore.src">
								<img src = "images/del_before.png" alt="Add Cycle" name = "delbut" width="156" height="34"/>
							</a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	
	<div class="footer">
		<div class="padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
	</div>
		
</div>
</body>
</html>

This the 2 related files. Whenever I input the correct username and password, it will redirect me back to the admin.php as if the username and password is wrong. Please help.

This article has been dead for over six months. Start a new discussion instead.