我已经编写了一个注册系统,现在正在页面上更新配置文件。麻烦的是,当您提交表单时,处理页面绝对是空白的。根本没有文字,根本没有处理。任何人都可以帮忙解决问题吗?
usercp.php
<form action="doUser.php" method="post">
<strong>Email</strong><br>
<input type="text" value="<?php echo $e; ?>" name="email"><br>
<strong>Please enter password to confirm</strong><br>
<input type="password" name="pass"><br>
<input type="submit" value="Go!"></form>
doUser.php
<div id="content">
<p>What is going on</p>
<?php
$e = $_POST["email"];
$p = $_POST["pass"];
echo $e;
if(isset($e)) {
$query = $db->prepare("SELECT pass FROM users WHERE id=:i");
$query->bindParam(':i',$i);
$query->execute();
$result=$query->fetch();
$password = $result['pass'];
$check = password_verify($p, $password);
if($check) {
$query->prepare("UPDATE users SET email=':e'");
$query->bindParam(':e', $e);
$query->execute();
header("Location: usercp.php");
}
else {
echo "Incorrect password.";
}
else {
echo "You didn't enter a new email.";
}
?>
</div>
芯/的init.php
<?php
session_start();
$db = new PDO('login data is fine');
if(isset($_SESSION['id'])) {
$i = $_SESSION['id'];
}
else {
echo "Please <a href='login.php'>log in.</a>";
$guest = True;
}
答案 0 :(得分:2)
当您已向用户发送一些数据时,不可以使用header()。
<div id="content">
<p>What is going on</p>
<?php
$e = $_POST["email"];
$p = $_POST["pass"];
echo $e;
if(isset($e)) {
$query = $db->prepare("SELECT pass FROM users WHERE id=:i");
$query->bindParam(':i',$i);
$query->execute();
$result=$query->fetch();
$password = $result['pass']; //is this key exists?
$check = password_verify($p, $password); //is this function exists?
if($check) {
$query->prepare("UPDATE users SET email=':e'");
$query->bindParam(':e', $e);
$query->execute();
header("Location: usercp.php"); //because this won't work
}
else {
echo "Incorrect password.";
}
else {
echo "You didn't enter a new email.";
}
?>
</div>
此外,在顶部添加
error_reporting(E_ALL);
ini_set('display_errors', 1);
你会知道什么是错的
答案 1 :(得分:0)
尝试在doUser.php上设置更多错误报告,因为我认为问题是在尝试回显数据后使用header()。标题只能在任何HTML之前使用...