duancan1732 2015-01-02 10:40
浏览 63
已采纳

php isset($ _ post)无效? [关闭]

I am working with this issue since last few hours and also searched the related questions on stack overflow. I have a simple html form

<form name="user_verification" action="action.php" method="POST">
 Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" name="submit" value="submit">
</form>

and here is the php script in action.php file

if(isset($_POST['submit'])) 
{
echo 'yes';
}else{
echo 'no';
}

It always display "no". I tested my php script using this

 if(1==1) 
    {
    echo 'yes';
    }else{
    echo 'no';
    }

In this case, it displays "yes". This means that problem is with isset($_POST['submit']) function but I can't find out the solution. please help in this regard. thanks

  • 写回答

5条回答 默认 最新

  • duanfangfei5558 2015-01-02 11:09
    关注

    For robustness its best to check the method against the request.
    This is a simple example of a form processor validating a post request.

    if ('POST' === $_SERVER['REQUEST_METHOD']) {
        if (!isset($_POST['required_data'])) {
            http_send_status(400);
            exit;
        }
    
        echo 'OK';
    }
    

    You will still need to check with isset against the fields you require.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?