Warning: Cannot modify header information - headers already sent by (output started at path/development/load/dologin.php:14) in path/development/load/dologin.php on line 33 <?php session_start();?><html xmlns="http://www.w3.org/1999/xhtml"><head><LINK href="includes/css/style.css" rel="stylesheet" type="text/css"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Login</title></head><body><div id="header">PaymentINC</div><?phpinclude("dbsettings.php"); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $sql="SELECT * FROM `user` WHERE `username`='{$username}' AND `password`='{$password}'"; $result=mysql_query($sql); // do the check if($result) { if(mysql_num_rows($result) == 1) { $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location: account.php"); exit(); } else { echo "Wrong username/password."; } } else { echo "The query is not true."; } ?> PHP:
u can use header() and session_start() only before giving any output through ur page.. in this case session_start is fine but u can't use header()
Move all of your code into the first PHP block. Instead of directly echoing, save your response text to a variable. Then, in the page, just echo the variable.
<?php session_start();?><?php include("dbsettings.php"); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $sql="SELECT * FROM `user` WHERE `username`='{$username}' AND `password`='{$password}'"; $result=mysql_query($sql); // do the check if($result) { if(mysql_num_rows($result) == 1) { $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location: account.php"); exit(); } else { echo "Wrong username/password."; } } else { echo "The query is not true."; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <LINK href="includes/css/style.css" rel="stylesheet" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> </head> <body> <div id="header">PaymentINC</div> Code (markup): What do you get when you use that?
you should separate html and php codes in separate files. Then include html into the php. Suggestion: use header() before any header manipulation, so include('html') after header().