duanke6057 2017-04-06 12: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

<div class="modal fade" id="modalWriteFeedback" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <form action="php/feedbackPHP.php" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h3 class="modal-title" id="modalTitleWriteFeedback">Create New Feedback</h3>
                </div>
                <div class="modal-body" id="modalContentWriteFeedback">
                    <div class="form-group">
                        <label for="txtFeedback">Title:</label>
                        <input name="title" class="form-control required" type="text" id="txtFeedback">
                    </div>
                    <div class="form-group">
                        <label for="feedbackText">Description:</label>
                        <textarea class="form-control required" id="feedbackText" rows="15" name="content"></textarea>
                    </div>
                    <input type="submit" class="btn-success" name="btnSendFeedback" value="Send">

                </div>
            </div>
        </form>
    </div>
</div>

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

feedbackPHP.php

<?php
$servername = "*********";
$username = "**********";
$password = "***********";

    // Create connection
$db = new mysqli($servername, $username, $password);

    // Check connection
if ($db->connect_error) {
       die("Connection failed: " . $db->connect_error);
}

$feedbackTitle = $_post['title'];
$feedbackContent = $_post['content'];
$query = /**inserting data in db**/;

echo $feedbackTitle . "<- supposed to not be empty";

mysqli_query($db, $query) or die('msg:' + $feedbackTitle);

//Step3
$result = mysqli_query($db, $query);
mysqli_close($db);

?>

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

I have tried with a simple form:

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

With this as .php

<?php
/**connect to db part**/

$feedbackTitle = $_POST['title'];
$feedbackContent = $_POST['content'];

echo $feedbackTitle . " " . $feedbackContent;

$query = /**insert into db**/;

mysqli_query($db, $query) or die('msg:' + $feedbackTitle);

//Step3
$result = mysqli_query($db, $query);
mysqli_close($db);

?>

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 12: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

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭