使用localhost-is和php发送数据


sending data using localhost iis and php

我在使用php发送数据时遇到问题。我遵循一些学习php的在线教程,我遇到了一些问题。我相当确定php在我的iis localhost上运行良好,因为我从localhost运行了一个测试index.php,一切都恢复正常。我还将文件上传到了一个web服务器,在那里我知道php配置正确。我猜我的问题出在语法上。

文本"你的名字是"answers"你住在"显示得很好,但提交的内容都没有显示出来。我很确定这个问题确实是你的用户错误造成的。有什么建议吗?

以下是包含以下表单的php文件:

<html>
<head> 
    <title><?php echo "Form test";?></title>    
</head>
<body>
    <form action="http://localhost/php/phptest1.php" method="post">
      <p>Name:
      <input type="text" id="name" size="30 "value="">
      </p>
      <p>Address:
      <input type="text" id="address" size="30" value="">
      </p>
    </form>
</body> 
</html>

在这里他的php文件接收数据:

<html>
<head>
    <title><?php echo "I have the Info";?></title>
</head>
<body>
    <?php 
        echo "Your name is: ", $_POST['name'], "<br />";
        echo "You live at: ", $_POST['address'], "<br />";
    ?>  
</body>
</html>

您必须使用name属性而不是id:

  <input type="text" name="name" size="30" value="">

您的代码没有按照您希望的方式工作的原因是您的命名约定中有两个错误

表单字段需要添加name="some_name"(例如"some_name")。

更改

<input type="text" id="name" size="30 "value="">

到:

<input type="text" name="name" id="name" size="30 "value="">

<input type="text" id="address" size="30" value="">

到:

<input type="text" name="address" id="address" size="30" value="">

完整表单代码:

<html>
<head> 
<title><?php echo "Form test";?></title>    
</head>
<body>
    <form action="http://localhost/php/phptest1.php" method="post">
      <p>Name:
      <input type="text" name="name" id="name" size="30 "value="">
      </p>
      <p>Address:
      <input type="text" name="address" id="address" size="30" value="">
      </p>
    </form>
</body> 
</html>

添加了注意事项id可以保留在OP的代码中,用于CSS中的样式,如果以后需要进行样式设置,可以保留CCD_4。

5和CCD_ 6可以安全地去除。