2012-07-28 83 views
-4

可能重复:
Headers already sent by PHP重定向和头已经发出已

我的MySQL数据库有两个表:‘Listing’‘country_id’

‘Country’

‘Country’链接 '上市'

函数createrow()‘Listing’中创建一个新行,这是通过使用下拉选择框的'Submit'按钮完成的,然后将标题命令重定向到另一个页面。

出于某种原因,我不知道,如果表‘Country’包含超过35条记录,我收到以下错误消息(35 ps的记录头命令重定向没有错误):

警告:不能修改头信息 - 已在第113行的C:\ xampp \ htdocs \ MySQLprtnr \ create.php中输出的头文件(输出在C:\ xampp \ htdocs \ MySQLprtnr \ create.php:101开始)

代码:

; 
<input type="submit" name="Submit" value="Submit"></td> 
</tr> 

<?php 
if (isset($_POST['Submit'])) 
      { 
     $message = $_POST['message']; 
     $subject = $_POST['subject']; 
     $country_id = $_POST['country_id']; 
     createrow($message, $subject, $country_id); 
     header('Location: memberprofile.php'); 
     } 
?> 
</form> 
</table> 

Line nu mbers:

线#101:<?php

线#113:'header('Location: memberprofile.php');'

我有以下两个问题:

  1. 为什么我收到上述错误消息解释呢?
  2. 因为我没有问题#1的解决方案,有没有另一种方式来重定向,而不是'header'`(也许使用Javascript)?

感谢您的任何援助,

回答

1

只能其它任何输出前使用header('...');。在你的情况下,它应该是:

<?php //beginning of the file 
if (isset($_POST['Submit'])) { 
    $message = $_POST['message']; 
    $subject = $_POST['subject']; 
    $country_id = $_POST['country_id']; 
    createrow($message, $subject, $country_id); 
    header('Location: memberprofile.php'); 
} 
..... 
?><!DOCTYPE .... 
<HTML>.... 
.....