This question has already been answered:
Good day. I do not understand what the error is in the code. In the browser, an error occurs when redirecting to another file - Cannot modify header information - headers already sent by. Explain where I nakosyachil? I searched the Internet for information, I understood about the essence of the error, but I don’t know how to fix it. Already the html code was deleted, and I looked at all the spaces with empty lines, I can not understand what the problem is.
<!DOCTYPE HTML> <html> <meta charset="utf-8"> </html> <?php if (isset($_POST['login'])) { $login = $_POST['login']; } if (isset($_POST['password'])) { $password=$_POST['password']; } $login = stripslashes($login); $login = htmlspecialchars($login); $password = stripslashes($password); $password = htmlspecialchars($password); $login = trim($login); $password = trim($password); include ("bd.php"); $result = mysql_query("SELECT * FROM users WHERE login='$login'",$db); $myrow = mysql_fetch_array($result); if (empty($myrow['password'])) { exit ("Извините, введённый вами login или пароль неверный."); } else { if ($myrow['password']==$password) { $_SESSION['login']=$myrow['login']; $_SESSION['id']=$myrow['id']; //echo "Вы успешно вошли на сайт! <a href='index.php'>Главная страница</a>"; header('Location: http://localhost/practice/main.php/'); exit; } else { exit ("Извините, введённый вами login или пароль неверный."); } } ?>
<?phptag in your example after the code. That is, first execute the code, decide what will be on the page, and only then output when you have already decided and considered everything - wirtwelt<?phptag there are no spaces or empty lines. All HTML should be located under php. - Edward