Hi I'm doing a PHP for log in function and I got this error I have tried every possible ways to fix this problem from Googling the solutions but I still can't fix the problem , anyone can help me? I'm using PHP 5 <?php if(!isset($empID) || !isset($empPass)) { header("Location: empLogin.php"); } elseif(empty($empID) || empty($empPass)) { header("Location: empLogin.php"); } else { $user = assslashes($_POST['empID']); $pass = md5($_POST['empPass']); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("emplogin", $con); $result=mysql_query("SELECT * from emplogin WHERE empID='$empID' AND empPass='$empPass'", $con); $rowCheck = mysql_num-rows($result); if($rowCheck > 0) { while($row = mysql_fetch_array($result)) { session_start(); session_register('empID'); echo "Welcome!"; header("Location: empHome.php"); } } else { echo "Please try again"; } } ?> PHP:
echo "Welcome!"; header("Location: empHome.php"); PHP: You can't echo something and use header() after. header() must be called only if no content was sent to the browser.
i have removed echo but it still returns the same warning, i wonder if this is because i include the codings within html tag?
so i tried to put all of the php code on top of the html tag but it returns nothing, it went back to the login page
i got it already, gosh i'm so slow lol the header function is used to redirect user into the given page
i tried it too but that was before i put the php codes outside html tag, can ob_start() be used if the php codes within the html tag?
Below code is creating problem for tou. echo "Welcome!"; header("Location: empHome.php"); PHP: You can not use header after anything sent to the user(i.e. browser). So header must be the last line of the execution. As better practice user exit after header call.
Almost the same as all the above, 1. Header can only be sent once. so it's not about the echo, it's not about anything elses. It's about you're sending header call after it actually being sent before, php wont send this second header call. so it warns you. in plain english php would probably says sumthin like this : So, all you need to figure is, which was your first header call? and which is your next one you've trying to send after. From xpertdev pointers, I assume the 2nd one would be the header("Location: empHome.php"); PHP: ..where in this line, I also assume you're trying to redirect a user to empHome.php, when something/some process is done. While actually, you've already sent a header call before. I'm not quite sure which one is the first which one is the next - you should know which one which, coz you're the one who wrote the piece. But here's the next pointer, you can either : - rewrite your code to redirect the user using syntax other than header - location. - rewrite the first header call into sumthing else, can't suggest you what,as i 'm not sure of which As confusing as those above writing - Hope it gives you another point of view.