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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试