简体   繁体   English

表单提交按钮在PHP中不起作用

[英]FORM Submit button not working in php

code is working properly. 代码正常工作。 When it times to press the submit button it didn't give any answer or error. 按下提交按钮时,它没有给出任何答案或错误。 I'd also tried to change the form< action="..." > and place the result in another file but it didn't show anything. 我还尝试过更改表单<action =“ ...”>并将结果放置在另一个文件中,但未显示任何内容。

<form action= "" methods="post">
<!-- image section start from here -->
  <div class="desc"> E-LN3465 <br/> PRICE: 5000 Pkr <br/><input type="text" name="E-LN3465"  value="1" /> </div>

  <div class="desc">E-LN7645 <br/> PRICE: 4000 Pkr <br/><input type="text" name="E-LN7645"  value="1" /></div>

 <div class="desc">E-LN7644 <br/> PRICE: 5000 Pkr<br/><input type="text" name="E-LN7644"  value="1" /></div>

  <div class="desc">E-LN3456 <br/> PRICE: 8000 Pkr <br/><input type="text" name="E-LN3456"  value="1" /> </div>

  <div class="desc">E-LN7863 <br/> PRICE: 4900 Pkr <br/><input type="text" name="E-LN7863"  value="1" /></div>


  <div class="desc">E-LN6709 <br/> PRICE: 5000 Pkr<br/><input type="text" name="E-LN6709"  value="1" /> </div>



                <p><input type="submit"  name=" submit" value="Add to cart" /></p>
<?php
            if(isset($_POST['submit']))
            { echo $_POST['E-LN6709'];  }
?>


</form>

NB: Making this as a community wiki. 注意:将其作为社区Wiki。 I feel there should be no personal gain from this answer. 我觉得从这个答案中不会有个人收益。

As outlined in comments: 如评论所述:

  • Use method="post" (without the s in method ). 使用method="post" (不带smethod )。 – D4V1D – D4V1D

  • also, <input type="text" name="E-LN6709" value="1" / needs a > on the end – Adam 另外, <input type="text" name="E-LN6709" value="1" /需要一个> – Adam

But this one I caught after: 但是我追赶的是:

name=" submit"

Your conditional statement will fail because of the space in there. 您的条件语句将因为其中的空间而失败。

  • Remove it name="submit" 删除它name="submit"

Add error reporting to the top of your file(s) which will help find errors. 错误报告添加到文件顶部,这将有助于发现错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Displaying errors should only be done in staging, and never production. 旁注:显示错误仅应在登台中进行,而不应在生产中进行。

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

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