bambinou1980 Posted July 16, 2015 Share Posted July 16, 2015 (edited) Hello, I keephaving this annoying error and cannot work out why it is happening, any help would be more than appreciated please. I looked online for help but cannot work out why data cannot be sent before the header or why there is data anyway sent before the header code....I am confused. I checked for blank spaces and things like that but nothing... Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\plus\admin\includes\header.php:21) in C:\xampp\htdocs\plus\admin\sign-in.php on line 29 <?phpsession_start();include('includes/header.php');include('includes/public-navbar.php');include('../db/dbconnect.php');?> <?php $username = ""; if(isset($_POST['submit'])) { //process the form if(isset($_POST["username"]) && $_POST["password"]) { $query = "SELECT * FROM users WHERE username = 'admin' LIMIT 1"; $results = mysqli_query($connection, $query); $password = $_POST["password"]; $admin = $_POST["username"]; while ($row = mysqli_fetch_row($results)) { //If Admin name = md5 mysql recorded version if(md5($password) != $row[2]) { echo "wrong username/password!"; }else{ header("Location: logged-in.php"); die(); } } } } ?> <!--Content--> <div class="row"><div class="col-md-4"></div><div class="col-md-4"> <form role="form" method="post" action="sign-in.php"><div class="form-group"> <label for="InputUsername">Username</label><input type="text" class="form-control" name="username" placeholder="Your Email" value="<?php echo htmlentities($username); ?>" required /></div> <div class="form-group"> <label for="InputPassword">Password</label><input type="password" class="form-control" name="password" placeholder="Your Password" required /></div> <div class="form-group"> <button type="submit" class="btn btn-default" name="submit">Submit</button> </div></form></div><div class="col-md-4"></div></div> <!--Content--> <?php include('includes/footer.php'); ?> and here is my header.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Admin Login</title> <meta name="description" content=""> <meta name="author" content=""> <link href="../css/bootstrap.min.css" rel="stylesheet"> <link href="../css/style.css" rel="stylesheet"> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> Edited July 16, 2015 by bambinou1980 Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 16, 2015 Share Posted July 16, 2015 If this is the code for the entire page, then remove the blank lines at the top of the page before the opening <?php tag. Make the <?php the first thing on the page. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 16, 2015 Share Posted July 16, 2015 output started at C:\xampp\htdocs\plus\admin\includes\header.php:21 everything that is in your header.php file is output that's being sent to the browser. line 21 is just the end of all the output. the best way of correcting this is to layout your page with any php code that determines what your page will do (the control logic), first. then put any php code that gets/produces the content on the page and the actual html/css/javascrpt markup at the end. your form processing code is part of the control logic that determines what your page will do and it should come before the <!DOCTYPE html> tag. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.