raptor30506090 Posted September 17, 2011 Share Posted September 17, 2011 Can some one help please i always get this wrong dont now why keep saying header already been sent any help please and how to fix it <?php session_start(); $conn = mysql_connect(""); $db = mysql_select_db("", $conn); if(isset($_POST['submit'])){ $user = mysql_escape_string($_POST['user']); $pass = mysql_escape_string($_POST['pass']); } if(empty($user) && empty($pass)){ exit; }else{ } ?> <?php $sql = mysql_query("SELECT * FROM useradmin WHERE dbusername= '".$user."' AND dbuserpass= '".$pass."'")or die(mysql_error()); $row = mysql_fetch_assoc($sql); $count = count($sql); $u = $row['dbusername']; $p = $row['dbuserpass']; if($u == $user && $p == $pass){ $_SESSION['access'] = "$u"; header("location: index.php"); }else { echo "Sorry there as been a problem!"; exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/ Share on other sites More sharing options...
JKG Posted September 17, 2011 Share Posted September 17, 2011 you are outputting empty chars. if(empty($user) && empty($pass)){ exit; }else{ } ?> <?php $sql should be if(empty($user) && empty($pass)){ exit; }else{ } $sql why open and close the tags?? any characters before a header statement will throw this error. Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/#findComment-1270238 Share on other sites More sharing options...
raptor30506090 Posted September 17, 2011 Author Share Posted September 17, 2011 Hi the open and close tags was just trying to get rid of error what do you mean characters before a header ? can you show me an example of the best way round please Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/#findComment-1270243 Share on other sites More sharing options...
Pikachu2000 Posted September 17, 2011 Share Posted September 17, 2011 Get rid of the empty else{} and remove the unnecessary close/open php tags that follow it and see what you get. If that doesn't take care of it, copy/paste the error message here. Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/#findComment-1270248 Share on other sites More sharing options...
JKG Posted September 17, 2011 Share Posted September 17, 2011 if what you have posted is your entire header then removing the <?php ?> tags will fix it. If you have other content in between the tags then it will not work. You cannot output any character whatsoever before sending a header(). so if you do this: echo ' '; header (foo); it will fail. if you do this: <?php header(foo); ?> it will fail. (notice the space before <) Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/#findComment-1270249 Share on other sites More sharing options...
raptor30506090 Posted September 17, 2011 Author Share Posted September 17, 2011 This is the error it says Warning: Cannot modify header information - headers already sent by (output started at /home/content/80/5047580/html/webdazsign/admin/script/loginS.php:13) in /home/content/80/5047580/html/webdazsign/admin/script/loginS.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/#findComment-1270261 Share on other sites More sharing options...
raptor30506090 Posted September 17, 2011 Author Share Posted September 17, 2011 Thank you for your help i understand now how it works breaking code leaving gaps closed it all up works great Quote Link to comment https://forums.phpfreaks.com/topic/247333-header/#findComment-1270262 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.