2012-07-28 60 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>.... 
.....