Ptsface12 Posted July 22, 2011 Share Posted July 22, 2011 Hey, For some reason I got the following error: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\index.php:5) in C:\xampp\htdocs\index.php on line 37 Line 37: header('location: me.php'); My code is: <?php session_start(); include 'includes/core.php'; ?> <head> <title><?php echo $_SESSION['shortname']; ?> » Home </title> <link rel="stylesheet" href="css/login.css" /> </head> <body><div id="container"> <div id="head"> <a href='index.php'> <div id='logo'> </div> </a></div> <div id="login_background"> <div id="login">New to <?php echo $_SESSION['shortname']; ?>? <strong><u><a href="register.php">REGISTER HERE! </a></u></strong><br /> <?php if (isset($_POST['log_button'])) { $user = $_POST['username']; $pass = $_POST['password']; include ('includes/config.php'); $con = mysql_connect($host, $dbuser, $dbpass) or die("Unable to connect!"); mysql_select_db($db, $con); $sql="SELECT * FROM users WHERE username='$user' and password=MD5('$pass')"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['username'] = $user; header('location: me.php'); } else { echo "Wrong Username or Password"; } } ?> <br /> <form method="post"> <p>Username :<br /> <input type="text" name="username" id="username" value="Username" onFocus="if (this.value == 'Username') this.value = '';" /> </p> <p> Password:<br /> <input type="password" name="password" id="username" value="Password" onFocus="if (this.value == 'Password') this.value = '';" /> <br /> </p> <center><align='right'><input type="submit" name="log_button" value="Sign In" /></align></center> </form> </div> </div> </div> <br /> </body> Any help is appreciated! Best Wishes, Ptsface12 Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/ Share on other sites More sharing options...
premiso Posted July 22, 2011 Share Posted July 22, 2011 http://www.phpfreaks.com/forums/index.php?topic=37442.0 Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/#findComment-1246351 Share on other sites More sharing options...
AdRock Posted July 22, 2011 Share Posted July 22, 2011 You can't have html before headers need to be sent Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/#findComment-1246353 Share on other sites More sharing options...
AdRock Posted July 22, 2011 Share Posted July 22, 2011 <?php if (isset($_POST['log_button'])) { $user = $_POST['username']; $pass = $_POST['password']; include ('includes/config.php'); $con = mysql_connect($host, $dbuser, $dbpass) or die("Unable to connect!"); mysql_select_db($db, $con); $sql="SELECT * FROM users WHERE username='$user' and password=MD5('$pass')"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['username'] = $user; header('location: me.php'); } else { $message = "Wrong Username or Password"; } that need to be near the top before any html is displayed then where you want message if applicable if(isset($message)) echo $message; Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/#findComment-1246355 Share on other sites More sharing options...
Ptsface12 Posted July 22, 2011 Author Share Posted July 22, 2011 Hello, I don't get where you add the message bit. I want my message to say that their username failed if couldn't select. How could I ask this? best wishes, Ptsface12 Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/#findComment-1246358 Share on other sites More sharing options...
Ptsface12 Posted July 22, 2011 Author Share Posted July 22, 2011 Hello, Can someone help me please, I don't know where to put this Best Wishes, Ptsface12 Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/#findComment-1246370 Share on other sites More sharing options...
dcro2 Posted July 22, 2011 Share Posted July 22, 2011 Put if(isset($message)) echo $message; where the echo was before, right above the form. <?php //here ?> <br /> <form method="post"> <p>Username Quote Link to comment https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/#findComment-1246385 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.