简体   繁体   English

PHP Post不起作用/ Get

[英]PHP Post doesn't work / Get does

I am new to php programming. 我是php编程的新手。 I have been trying to learn from w3 schools. 我一直在努力向w3学校学习。 I have installed phpstorm on my mac. 我在我的mac上安装了phpstorm。 I have been learning forms. 我一直在学习表格。 the code is below 代码如下

Form: 形成:

<form action="welcome.php" method="post">
    Name: <input type="text" name="name" id="name"> <br>
    E-mail: <input type="text" name="email" id="email"><br>
    <input type="submit">
</form> 

Message board: 留言板:

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

When I try and use post on the form, I get an error 当我尝试在表单上使用帖子时,我收到错误

Welcome 
Notice: Undefined index: name in /Users/chris/PhpstormProjects/three/welcome.php on line 4

Your email address is: 
Notice: Undefined index: email in /Users/chris/PhpstormProjects/three/welcome.php on line 5

But when I use get the code works perfectly. 但是当我使用get时代码完美无缺。 I use a Mac, I have tried changing from MAMP to XAMPP, have run the code in xampp and mamp and still nothing happens. 我使用Mac,我尝试从MAMP更改为XAMPP,在xampp和mamp中运行代码但仍然没有任何反应。 I am all out of ideas, can anyone help ? 我完全没有想法,有人可以帮忙吗?

Update 更新

This is not like any other problem on stack overflow ( believe me I've checked :-) ) 这不像堆栈溢出的任何其他问题(相信我,我已经检查:-))

From what can see , the HTML form is not writing to post which is odd as thats what I thought it should do , has anyone else come across this in phpstorm ? 从可以看到,HTML表单不写入post这是奇怪的,因为我认为它应该做什么,有没有其他人在phpstorm中遇到这个?

Many thanks again 非常感谢再次

After searching a lot of forums, there appears to be bugs with the internal PhpStorm web server that prevent posts from working, although, I am not certain of the circumstances. 在搜索了很多论坛之后,内部PhpStorm Web服务器似乎存在阻止帖子工作的错误,但是,我不确定这些情况。 I wasn't able to get simple or complex posts to work with my current setup (PHP 7 with PhpStorm 2016.2 built on July 12, 2016). 我无法获得简单或复杂的帖子来使用我当前的设置(PHP 7与PhpStorm 2016.2建立于2016年7月12日)。

Solution was to use a proper web server instead of the internal one. 解决方案是使用适当的Web服务器而不是内部服务器。 To do this: 去做这个:

  1. Define Deployment entry (Tools --> Deployment --> Configuration). 定义部署条目(工具 - >部署 - >配置)。 Set the type to be either "In place" or "Local or mounted folder" and ensure your web server to serve up your project files. 将类型设置为“就地”或“本地或装入的文件夹”,并确保您的Web服务器提供项目文件。
  2. Configure the remaining items by providing URL details for your web server configuration. 通过提供Web服务器配置的URL详细信息来配置其余项目。
  3. Click on "Use this server as default" on the Mappings tab. 单击“映射”选项卡上的“将此服务器用作默认值”。

Now the IDE will use that deployment option for Run & Debug actions for the current project and any future ones. 现在,IDE将为当前项目和任何将来的项目使用该部署选项进行运行和调试操作。 You may still need to reconfigure any other pre-existing projects you have manually. 您可能仍需要手动重新配置任何其他预先存在的项目。

I note that this issue can result in multiple errors including bad gateway, page not found and your undefined index error, but all three should be fixed by the same solution. 我注意到这个问题可能导致多个错误,包括错误的网关,找不到页面和未定义的索引错误,但这三个错误应该由同一个解决方案修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM