开机自检未填满

  • 本文关键字:开机自检 php post
  • 更新时间 :
  • 英文 :


问题

每当我点击提交按钮时,我都会填写POST,它应该会设置POST。但不幸的是,由于某些随机原因,它没有填充POST。

代码

        echo '
        <form action="settings.php" method="POST">
        <textarea name="area" class="input" id="textarea">'.$settings_welcome_page['paragraph'].'</textarea><br />
        <input type="submit" value="Edit" class="button">
        </form>';
        if (isset($_POST['area'])) {
            $update = $CONNECT_TO_DATABASE->prepare("UPDATE welcome_text SET paragraph = :message");
            $update->bindValue(':message', $_POST['paragraph']);
            $update->execute();
            header ('Location: settings.php?status=sucess');    
        } else {
            echo' post not working ';
        }

它正在返回回声"Post not working"。这意味着POST‘区域’没有被设置。

问题出在哪里?我该如何修复?谢谢

$_POST['paragraph']

应该是

$_POST['area']

在绑定的价值也在你的条件下,你可以广告

if(isset($_POST['area']) || (isset($_GET['status']) == 'success')){
    // code here..
} 
else{
   // code here..
}

让你看看你是否已经提交了表格,而不是陷入其他情况。

一般。。你的代码应该像这个

if (isset($_POST['area']) || (isset($_GET['status']) == 'succes')) {
            $update = $CONNECT_TO_DATABASE->prepare("UPDATE welcome_text SET paragraph = :message");
            $update->bindValue(':message', $_POST['area']);
            $update->execute();
            header ('Location: settings.php?status=sucess');    
        } else {
            echo' post not working ';
        }

这就是发生的情况:

  1. 您填写表格并单击"编辑">
  2. 表单被张贴并将数据放入数据库
  3. 您重新定位到同一页面,但没有POST(通过调用header函数(
  4. 您的页面显示出来,没有POST,显示为"POST not working">

要修复此问题,请删除header()调用,它将不会重新加载。

并引用正确的索引:$_POST['area']而不是$_POST['paragraph']

在您的代码中,您的服务器将通过重定向标头回答POST:

   if (isset($_POST['area'])) {
        header ('Location: settings.php?status=sucess');    
    } else {
        echo' post not working ';
    }

当浏览器接收到该报头时,GET settings.php?status=sucess被发送到服务器。这就是您收到post not working消息的原因。

如果你尝试这个代码,你会发现你的POST运行良好:

<html><body><?php 
 echo '
     <form action="settings.php" method="POST">
       <textarea name="area" class="input" id="textarea">bla bla ...</textarea><br />
       <input type="submit" value="Edit" class="button">
     </form>';
    if (isset($_POST['area'])) {
        echo' this was a POST of area='.$_POST['area'];
    } else {
        echo' this was a GET ';
    }
?></body></html>

相关内容

最新更新