我采用的是MVC模式的写法,代码和html分离的写法
<?php require ‘../mysql_connect.php‘;require(‘../model/functions.php‘);include_once ‘../views/login.html.php‘; if ($_SERVER[‘REQUEST_METHOD‘] == ‘POST‘) { ??// 处理表单 if (isset($_POST[‘login_submit‘])) { ???????$role = $_POST[‘role‘]; $username = $_POST[‘username‘]; ???????$passwd = $_POST[‘p‘]; ???if( user_login($pdo,$role,$username,$passwd) ){ ???????setcookie(‘userName‘,$name); ?????????????????????setcookie(‘password‘,$psw); ???????????header("location: index.php"); ?????}else{ ???????echo "<script>alert(‘输入信息错误,登录失败‘);</script>"; ???} }elseif (isset($_POST[‘get_password‘])) { ???????$email = $_POST[‘email‘]; ???????user_register($pdo,$email); }}
我在一个页面内写了两个form表单,但是两个表单都是提交到同一个PHP文件处理,到时提交第二个表单时就一直报这种错误,
解决方法:
只需要将第四行的html代码移到最后
PHP cannoy modify header information - headers already sent by ....
原文地址:https://www.cnblogs.com/ryanzheng/p/8224025.html