0

此 php 文件看似正确,但返回“文件意外结束”错误。是 html 文件中某处的错误。我尝试将标签放在“”中的 print 中,删除了 php 行上的一个额外空格,在变量行上的括号 [] 和引号''之间添加了空格,当我按 enter 时仍然有相同的错误将数据发送到 php 脚本。这是html代码: http: //pastebin.com/Rb62pZcy

<!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>

4

1 回答 1

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>";

我想你错过了“;” 特点。

- - - - - - - - - 更新 - - - - - - - - - - - - - - -

我尝试这段代码并且有效:

<!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  

在我的本地主机上工作.....如果您的问题继续存在,那么问题可能出在提交页面中。

萨卢多斯。

于 2013-03-21T00:56:20.507 回答