我的代码执行了(条目已插入数据库),但没有重定向到page.php。回声韦尔多工作,但标头功能不能。我怀疑ob_start()并在使用它后仍未重定向。我错了什么或想念什么?谢谢。
<?php session_start();?>
<?php include "connection.php";?>
<?php ob_start(); ?>
<?php
try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $loginame, $pw);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO database (username, password, name,
lastname, email, Title, Birth_Day, Birth_Month, Birth_Year, State, marital_status, gender, maiden)VALUES (:username, :password, :name, :lastname, :email, :Title, :Birth_Day, :Birth_Month, :Birth_Year, :State, :marital_status, :gender, :maiden)
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':Title', $title);
$stmt->bindParam(':Birth_Day', $Birth_Day);
$stmt->bindParam(':Birth_Month', $Birth_Month);
$stmt->bindParam(':Birth_Year', $Birth_Year);
$stmt->bindParam(':State', $state);
$stmt->bindParam(':marital_status', $maritalstatus);
$stmt->bindParam(':gender', $gender);
$stmt->bindParam(':maiden', $maiden);
$stmt->execute();
$_SESSION["username"] = $username;
// echo "weeldo";}
header("location: page.php");ob_end_clean();}
catch(PDOException $e){echo "Error: " . $e->getMessage();}
$conn = null;}?>