PHP注册表重定向到新页面

时间:2015-03-18 16:14:37

标签: php jquery html mysql forms

我在Mac上运行我的loacalhost服务器并且有一个使用PHP的注册表单的站点。我打算在用户提交表单时打开一个新的欢迎页面。

PHP代码是:

<?php
include('connect.php');
ob_start();
// If the values are posted, insert them into the database.
if (isset($_POST['username']) && isset($_POST['password'])){
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    $query = "INSERT INTO `users` (username, password, email) VALUES ('$username', '$password', '$email')";
    $result = mysql_query($query);
    if($result){
        header('Location: /welcome.html');
        echo '<script language="javascript">';
        echo 'alert("User Successfully Added")';
        echo '</script>';
    }
}
?>

单击“提交”按钮时,它实际上会向用户保存数据库(它在PHPmyAdmin中填充表格行),但在显示消息时它会保留在注册页面上:

  

警告:无法修改标头信息 - 第73行/Users/Stephen/Sites/tidy_map/register.php中已经发送的标头(在/Users/Stephen/Sites/tidy_map/register.php:61中开始输出)< / p>

第73行是:header('Location:/welcome.html');

0 个答案:

没有答案