duanke6057 2017-04-06 04:01
浏览 70
已采纳

$ _Post似乎在表单提交php后没有返回变量

fairly new php user here.

I've been struggling to find the solution to a very simple problem.

I'm currently creating a feedback system for my school where people can submit a text with a title to certain students, yet after submitting the form it seems the $_Post of my fields are empty.

My html looks like this (The form to be submitted is in a bootstrap modal)

HTML

  1. <div class="modal fade" id="modalWriteFeedback" tabindex="-1" role="dialog">
  2. <div class="modal-dialog" role="document">
  3. <form action="php/feedbackPHP.php" method="post">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  7. <h3 class="modal-title" id="modalTitleWriteFeedback">Create New Feedback</h3>
  8. </div>
  9. <div class="modal-body" id="modalContentWriteFeedback">
  10. <div class="form-group">
  11. <label for="txtFeedback">Title:</label>
  12. <input name="title" class="form-control required" type="text" id="txtFeedback">
  13. </div>
  14. <div class="form-group">
  15. <label for="feedbackText">Description:</label>
  16. <textarea class="form-control required" id="feedbackText" rows="15" name="content"></textarea>
  17. </div>
  18. <input type="submit" class="btn-success" name="btnSendFeedback" value="Send">
  19. </div>
  20. </div>
  21. </form>
  22. </div>
  23. </div>

"title" and "content" are to be submitted, which I'm trying in my "feedbackPHP.php"

feedbackPHP.php

  1. <?php
  2. $servername = "*********";
  3. $username = "**********";
  4. $password = "***********";
  5. // Create connection
  6. $db = new mysqli($servername, $username, $password);
  7. // Check connection
  8. if ($db->connect_error) {
  9. die("Connection failed: " . $db->connect_error);
  10. }
  11. $feedbackTitle = $_post['title'];
  12. $feedbackContent = $_post['content'];
  13. $query = /**inserting data in db**/;
  14. echo $feedbackTitle . "<- supposed to not be empty";
  15. mysqli_query($db, $query) or die('msg:' + $feedbackTitle);
  16. //Step3
  17. $result = mysqli_query($db, $query);
  18. mysqli_close($db);
  19. ?>

The submit recognized the .php file, and only returns the "<- supposed to not be empty" part.

I have tried with a simple form:

  1. <form action="php/feedbackPHP.php" method="POST">
  2. <input type="text" name="title" id="txtText">
  3. <input type="textarea" name="content" id="txtContent">
  4. <input type="submit" value="go">
  5. </form>

With this as .php

  1. <?php
  2. /**connect to db part**/
  3. $feedbackTitle = $_POST['title'];
  4. $feedbackContent = $_POST['content'];
  5. echo $feedbackTitle . " " . $feedbackContent;
  6. $query = /**insert into db**/;
  7. mysqli_query($db, $query) or die('msg:' + $feedbackTitle);
  8. //Step3
  9. $result = mysqli_query($db, $query);
  10. mysqli_close($db);
  11. ?>

And $feedbackTitle & $feedbackContent are working perfectly, even adding the right values in my database.

So according to this is it a problem with the bootstrap modal and the form in it?

I have tried with an Ajax request, the $_POST still seem to be empty. I tried almost every answer on the forum (been busy for almost a day now), but none seem to be working either.

Thanks in advance.

</div>

展开全部

  • 写回答

1条回答 默认 最新

  • download201401 2017-04-06 04:04
    关注

    Use $_POST, not $_post :-)

    Php is case sensitive, and it will be the same with $_GET, $_SESSION, $_SERVER, [...]

    http://php.net/language.variables.superglobals

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部