我使用'include'命令調用了一個PHP文件中的多個表單。如果我將include命令放在HTML頁面中的其他表單之前,那麼它就可以工作。問題是我需要在其他表單下面調用'include'命令。我想出的解決方案是在頁面的開頭調用PHP文件並隱藏div。然後我在頁面底部再次調用該文件來解決問題。還有其他解決方案嗎?它爲什麼這樣做?當其他表單被調用時,PHP表單調用HTML文件不起作用
非工作示例:
<form></form>
<form></form>
include 'phpfilewithotherforms.php';
工作的例子,但並不可行:
include 'phpfilewithotherforms.php';
<form></form>
<form></form>
工作示例:
<div style="display:none;">include 'phpfilewithotherforms,php';</div>
<form></form>
<form></form>
include 'phpfilewithotherforms.php';
PHP文件的樣品是我打電話:
while($row = mysql_fetch_array($result))
{
echo "<div style='padding:20px;margin:15px;background:offwhite;border-style:solid;border-width:1px;border-color:lightgray;'>" .
"<form method='post' name='example'>" .
"<span class='detail'><b>Title:</b> " .
$row['mytitle'] .
" " .
"<input type='hidden' value='" . stripslashes($row['mytitle']) . "' . name='title'>" .
"<span style='float:right'>" .
"<input type='submit' value='Edit' name='edit'>" .
"<input type='submit' value='Preview' name='preview'>" .
"</span>" .
"</form>" .
}
也許使用輸出緩衝來防止數據在完成html頁面生成之前發送到瀏覽器。 – Danny
我有一個類似的問題,就像Danny說的那樣,我使用ob_start和ob_flush強制按順序訪問瀏覽器。這是我唯一的解決方法,從來沒有發現它爲什麼不起作用,因爲我嚴格測序了
謝謝你們。使用php緩衝區做了訣竅。 – Jeight