Hello guys..
im new to php and this is the first time im making a php website for my project
i made a php code for login but its not working.. the error message pop up everytime i tried to log in

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Project\index.php:20) in C:\xampp\htdocs\Project\index.php on line 45

i looked at everything but yea.. i still cant fix it..
i search for any other solution but it doesnt help me at all..
i hope u guys can help me solve this problem.. heres the code

thanks in advance..

(im using dreamweaver and editing most of it from templates)

<?php
// Inialize session
session_start();
// Check, if user is already login, then jump to secured page
if (isset($_SESSION['username'])) {
header('Location:M_index.php');
}
?><?php
//opening connection
require_once("dbconnect/database.php");
?>

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/public.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<link rel="stylesheet" type="text/css" href="css/public.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Home</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<!-- InstanceParam name="header" type="text" value="" -->
</head>

<body>

<?php
session_start(email);
//log in
//username
if($_POST['Enter']){
$myemail=$_POST['myemail'];
$mypw=$_POST['mypw'];
$myemail=stripslashes($myemail);
$mypw=stripslashes($mypw);
$myemail =mysql_real_escape_string($myemail);
$mypw = mysql_real_escape_string($mypw);
$sql="SELECT * FROM tbl_users WHERE myemail='$myemail' and mypw ='$mypw'";
$result = mysql_query($sql);
//mysq_num_row is counting table now
$count = mysql_num_rows($result);
if($count==1){
session_register("myemail");
session_register("mypw");
header("location:index.php");
}else{

}
}
?>
<div id="container">
<div id="header">

<ul><form name="loginForm" method="post">
<li><span style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E-mail:</span><input style="float:right;" type="text" name="myemail" /></li>
<li> <span style="float:left">&nbsp;Password:</span><input style="float:right;"type="password" name="mypw"/></li>
<li><span style="padding-left:200px;"><input type="submit" name="Enter"/></span></li></ul></form>
</div><!--End of Header-->

<div id="menu">
</div><!--End of menu-->

<div id="sidebar">

<ul>
<li><center><a href="index.php">Home</a></li></center>
<li><center><a href="about.php">About Us</a></li></center>
<li><center><a href="Contact.php">Contact Us</a></li></center>
<li><center><a href="Register.php">Register</a></center></li>
<li><center><a href="ofwguide.php">OFW guide</a></li></center>
<li><center><a href="onlineAppoff.php">Online Application</a></li></center>


</ul>
</div><!--End of sidebar-->

<div id="content"><!-- InstanceBeginEditable name="editBody" -->Home Page<!-- InstanceEndEditable -->
</div><!--End of content-->

</div> <!--End of Container-->

<?php
//closing connection
if(isset($dbcon)){
mysql_close($dbcon);
unset($dbcon);
}
?>
</body>
<!-- InstanceEnd --></html>

Not sure what you are trying to do on line 28 but for one you have already called session_start() on line 3 so you don't need to call it again, plus session_register is deprecated and you can shorten your code, try:

//log in
//username
if($_POST['Enter']){
$myemail=mysql_real_escape_string(stripslashes($_POST['myemail']));
$mypw=mysql_real_escape_string(stripslashes($_POST['mypw']));
$sql="SELECT * FROM tbl_users WHERE myemail='".$myemail."' and mypw ='".$mypw."'";
$result = mysql_query($sql);
//mysq_num_row is counting table now
$count = mysql_num_rows($result);
if($count==1){
$_SESSION['myemail']=$myemail;
$_SESSION['mypw']=$mypw;
header("location:index.php");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.