Hi Everyone,
Everytime I log into my website I always get the below error.
Cannot modify header information - headers already sent by ......
I thought maybe if my form submitted to another page it would work but it didn’t.
I thought if I echo’ed out the header information that would work but it didn’t. (instead of including it)
Below is my syntax. What am I doing wrong?
<?php
session_start();
include"connect_to_mysql3.php";
$loggedinuser = $_SESSION["id"];
$name = $_SESSION["name"];
include 'header.php';
/* echo '
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My Dynamic Website</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id=container>
<h1>My Dynamic WebSite</h1>
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="variables.php">Variables</a></li>
<li><a href="arrays.php">Arrays</a></li>
<li><a href="functions.php">Functions</a></li>
</ul>
</nav>'; */
/* include("edit-car-function-for-login2.php");
if (isset($_POST['name'], $_POST['password'])) {
$name = $_POST['name'];
$password =$_POST['password'];
loggeduser($name, $password);
} */
// $page = isset($_GET['page']) ? $_GET['page'] : 'home';
if (isset( $_POST['name'], $_POST['password'] )){
$name = $_POST['name'];
$password = $_POST['password'];
$password = sha1($password);
$name = mysql_real_escape_string($name);
$password = mysql_real_escape_string($password);
$sql_id = mysql_query("SELECT * FROM practice WHERE name='$name' AND password='$password'");
while($row = mysql_fetch_array($sql_id)){
$id = $row["id"];
}
$sql = ("SELECT id FROM practice WHERE name='$name' AND password='$password'");
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION["name"] = $name;
$_SESSION["id"] = $id;
header("location:heythere.php");
} else {
echo "Wrong Username and Password.";
}
}
?>
<?php
// include 'header.php';
?>
<?php
if ($loggedinuser != 0){
echo "Hi $name, your logged in! <br>";
echo "<p><a href=\\"http://whatsmyowncarworth.com/class-work/sign3/logout.php\\">Log Out</a></p>";
} else {
echo '<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="valchecklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><center><strong>Member Login </strong></center></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>';
}
?>
<?php
include 'footer.php';
?>