2013-03-21 44 views
0

此php文件顯示正確,但正在返回'文件意外結束'錯誤。該錯誤是否在html文件中。我試圖把內部打印標籤放在「」中,刪除了一行額外的空白空間,在可變行上的括號[]和引號''之間添加了空格,並且在按Enter鍵時仍然有相同的錯誤將數據發送到php腳本。下面是HTML代碼:http://pastebin.com/Rb62pZcy反饋表格HTML意外的文件結束PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>Your Feedback</title> 
</head> 
<body> 
<?php // Script 3.3 handle_form.php 
// This page receives the data from feedback.html 
// It will receive: title, name, email, comments in $_POST 

$title = $_POST [ 'title' ] ; 
$name = $_POST [ 'name' ] ; 
$email = $_POST [ 'email' ] ; 
$comments = $_POST [ 'comments' ] ; 

print "<p>Thank you, $title $name, for your comments.</p>" 
"<p>You stated that you found this example to be '$response' and added:<br />$comments</p>" 

?> 
</body> 

回答

0

取而代之的是:

print "<p>Thank you, $title $name, for your comments.</p>" 
"<p>You stated that you found this example to be '$response' and added:<br />$comments</p>" 

使用此:

echo "<p>Thank you, $title $name, for your comments.</p>"; 
echo "<p>You stated that you found this example to be '$response' and added:<br />$comments</p>"; 

我想你錯過了 「;」字符。

------------------ UPDATE --------------------------- -

我試試這個代碼和工作原理:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>Your Feedback</title> 
    </head> 
    <body> 
    <?php 

    if (isset($_POST['email'])){ 
    $title = $_POST['title']; 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $comments = $_POST['comments']; 
    } 
    else 
    { 
    $title = "No title arrived"; 
    $name = "No name arrived"; 
    $comments = "No comments arrived"; 
    } 

    //$response is not defined?? 
    $response = "Live long and prosper"; 
    //so i defined 

    echo "<p>Thank you, $title $name, for your comments.</p>"; 
    echo "<p>You stated that you found this example to be '$response' and added:<br />$comments</p>"; 
    ?> 
    </body> 

    </html> 

PS:嘗試單獨執行這個腳本...它命名爲 「handle_form.php」,並把這個在導航地址欄:

localhost/your_project/handle_form.php 

在我的本地主機上工作.....如果您的問題仍然存在,那麼問題可能出在提交頁面上。

Saludos。

+0

謝謝。我嘗試了你的建議,並給出了同樣的錯誤。 – 2013-03-21 02:12:33