weixin_33722405 2017-07-23 10:32 采纳率: 0%
浏览 38

$ _POST表单未提交数据[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined" dir="ltr">“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP</a>
                            <span class="question-originals-answer-count">
                                (28 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-07-23 10:58:23Z" class="relativetime">2 years ago</span>.</div>
        </div>
    </aside>

SO I am trying to build a very simple (semi) emailing system simply for practice and learning.

SO I have my nav bar with users personal info loading on the body (right side). Inside the nav bar there are clickable links to allow user to compose, read messages etc.

The links are appended with a PHP parameter as follows.

<a href="body.php?action=compose">

In the image below it is just a page load so for debugging purposes I use get not set, since no action has been taken (link clicked)

enter image description here

Now when user wants to compose an email and clicks compose, the following happens:

MY Logic

I get the action user wants to take via parameter appended to url in this case compose, so up comes a form allowing user to compose / sent a message to another user, which looks as follows:

enter image description here

I achieve this by the following code:

if($_SERVER['REQUEST_METHOD'] == 'GET'){
                if(isset($_GET['action'])){
                 //get which action user wants to take in this example compose email
                    $action = $_GET['action'];
                    if($action == 'compose'){
                        ?>
                        <form name="composeMsg" method="post" id="composeMsg" action="">
                        <input type="text" name="receipnt" placeholder="Receipnt" id="from">
                        <div class="break"></div>
                        <input type="text" name="subject" placeholder="Subject" id="subject">
                       <div class="break"></div>
                        <textarea placeholder="Message" name="msgBody" style="width: 350px; height: 200px">
                        </textarea>
                        <div class="break"></div>
                            <button type="submit" name="sendMsg" class="btn btn-danger">SEND</button>
                        </form>
                <?php
                        }
                       //submit button has been clicked
                        if(isset($_POST['sendMsg'])){
                         //execute script to send msg
                        $check = $msgClass->composeMsg('14', $_POST['receipnt'], $_POST['subject'], $_POST['msgBody'], date('Y-m-d') );
                        if($check ==  true){
                            echo '<h1>MSG SENT!</h1>';
                        }
                        elseif($check == false){
                            echo '<h1>OOPS...SOMETHING WENT WRONG!</h1>';
                        }
                    }//isset msgSent

My problem

All I get when sending message is a reloaded screen. No error, No Warnings and no script execution so I really dont know where to start my debugging.

I have tried to create a test page with just the email form and my composeMsg() method, which worked and inserted data into db. But when I implement it into my main page, when submit is clicked page just reloads without any action (as mentioned).

I have tried setting the form method to $_GET instead of $_POST but still same result

Any help appreciated!

Additional INfo

My method for send message looks as follows which is correct:

 public function composeMsg($userID, $toUser, $subject, $msg, $senton ){
        $db = DB::getInstance();
        $sql = "INSERT INTO messages (userID, fromID, subject, body, senton) values (:userID, :toUser, :subject, :msg, :senton )";
        $stmnt = $db->prepare($sql);

        $stmnt->bindValue(':userID', $userID);
        $stmnt->bindValue(':toUser', $toUser);
        $stmnt->bindValue(':subject', $subject);
        $stmnt->bindValue(':msg', $msg);
        $stmnt->bindValue(':senton', $senton);

        $stmnt->execute();

        if($stmnt->rowCount() > 0){
            return true;
        }
        else{
            return false;
        }
    }
</div>
  • 写回答

2条回答 默认 最新

  • weixin_33716154 2017-07-23 10:37
    关注

    Submitting your form takes you to your page without any GET Requests.

    <form name="composeMsg" method="post" id="composeMsg" action="">
    

    And since you wrap your POST Data submission with this:

    if($_SERVER['REQUEST_METHOD'] == 'GET'){
    

    It will never get there.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘