php header命令无效

use*_*424 2 php header

我在将该代码用于我即将推出的网站上时遇到问题.特别是当我登录时,成功登录后不会重定向.我以前使用过这段代码很多次,而且我从未遇到过这方面的问题.现在唯一的区别是我使用的是不同的服务器和不同的数据库.这是给我带来麻烦的代码:

<?php
/*set all the variables*/
$email = $_POST['email'];

$password = sha1($_POST['password']);   /* hash the password*/

$conn = mysqli_connect ('servername', 'username', 'password', 'databasename') or die('Error connecting to MySQL server');
/*select the id from the users table that match the conditions*/
$sql = "SELECT id FROM users WHERE email = '$email' AND password = '$password'";

$result = mysqli_query($conn, $sql) or die('Error querying database.');

$count = mysqli_num_rows($result);

if ($count == 1) {
echo 'Logged in Successfully.';

$row = mysqli_fetch_array($result);

session_start();

$_SESSION['user_id'] = $row['id'];

/*If true head over to the users table*/
header('location: users_table.php');


}
/*If invalid prompt them to adjust the previous entry*/
else {
echo '<h2>Invalid Login</h2><br />';
echo '<h2>Click <a href="javascript:history.go(-1)">HERE</a> to go back and adjust your entry.</h2>';
                    }


mysqli_close($conn);

?>
Run Code Online (Sandbox Code Playgroud)

这不是它正确连接的问题,因为我得到消息"成功登录"但它根本不会重定向.


感谢所有的答案,我尝试删除回声,但我现在得到的只是一个空白页,我想也许是我使用的浏览器所以我切换到另一个,我仍然只是得到一个空白页,任何其他建议?

Roc*_*mat 5

你的header陈述之前你不能回应任何事情.

echo 'Logged in Successfully.';
Run Code Online (Sandbox Code Playgroud)

这导致header呼叫无效.