larry ullman编写php for the web的第四版
第三章在表单处理这块
XXX.html中的内容是这样的:
 <!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>Feedback Form</title>
</head>
<body>
<!-- Script 3.2 - feedback.html -->
<div><p>Please complete this form to submit your feedback:</p><form action="handle_form.php" method="post"> <p>Name: <select name="title">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select> <input type="text" name="name" size="20" /></p> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Response: This is...
<input type="radio" name="response" value="excellent" /> excellent
<input type="radio" name="response" value="okay" /> okay
<input type="radio" name="response" value="boring" /> boring</p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send My Feedback" /></form>
</div>
</body>
</html>
handle_form.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, response, comments, and submit in $_POST.// Create shorthand versions of the variables:
$title = $_POST['title'];
$name = $_POST['name'];
$response = $_POST['response'];
$comments = $_POST['comments'];// Print the received data:
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>
</html>
结果我运行的和书上不一样 我自己写的是这样 用源码也是这样 浏览器是chrome 什么情况呢?环境是xampp搭建的

解决方案 »

  1.   

    在 print 前 加入这句 var_dump($_POST); 试下
      

  2.   

    不行啊 print的那句话直接没了就只剩下Thank you,$name。。
      

  3.   

    在php页上查看源代码 结果发现前面是绿色的 后面几个标签是紫色的?能反映出什么问题吗
    <?php // Script 3.3 handle_form.php // This page receives the data from feedback.html.// It will receive: title, name, email, response, comments, and submit in $_POST.// Create shorthand versions of the variables:$title = $_POST['title'];$name = $_POST['name'];$response = $_POST['response'];$comments = $_POST['comments'];// Print the received data:var_dump($_POST);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>";
      

  4.   

    确认php环境配置成功了?
    确认文件在根目录下吗? 怎么访问的?
      

  5.   

    是打开html表单然后填好信息提交 到handle_form.php
    我发现如果通过  
    http://localhost:80//handle_form.php 这种方式访问会变成这样也就是说这样子格式是对的 只不过没有前面html提供数据 但是如果用html访问就会出现开始那样的问题
    怎么回事呢?
      

  6.   

    我将html中的
    <form action="handle_form.php" method="post">
    改成
    <form action="http://localhost//handle_form.php" method="post">
    就成功了,可是书上就没有这么做 
    为什么?
      

  7.   

    目录没放对,你的 XXX.html 没在根目录下吧
      

  8.   

    根目录?不是应该放在xampp下的htdocs里面吗 
      

  9.   

    是的。你的两个文件是在 htdocs 下吗