【问题标题】:$_POST is not working on second page$_POST 在第二页上不起作用
【发布时间】:2017-09-15 00:02:11
【问题描述】:

- 已修复 -

当我提交表单时,我想在表格中编辑的行强制为 0 而不是设置 0 或 1(当我切换时)。这意味着表(行)以某种方式获得值 0。

这是我的表格:

<form class="form-horizontal" action="<?php echo BASE_URL?>process.php?task=edit_notify" method="post">
    <div class="form-group">
        <div class="material-switch pull-left">
            <p><span class="control-label" style="color: rgba(75, 75, 75, 0.6); cursor: default;"><?php echo ADMIN_NOTIFY; ?></span></p>
            <input id="allow_reg_msg" name="allow_reg_msg" type="checkbox" value="1" <?php if($row['allow_reg_msg'] == 1) echo "checked='checked'"; ?> />
            <label for="allow_reg_msg" class="label-primary"></label>
        </div>
    </div></br>
    <div class="form-group">
        <button type="submit" class="btn_"><i class="fa fa-pencil"></i> <?php echo EDIT; ?></button>
    </div>
</form>

当我提交时,它应该将值发送到 process.php 页面,这里是“process.php?task=edit_notify”:

if(isset($_GET['task']) && $_GET['task'] == "edit_notify"){
    if(!$user->isLoggedIn()) Redirect::to('index');
    if(!$user->hasPermission('admin')) Redirect::to('index');
    $allow_reg_msg = $_POST['allow_reg_msg'];
    $sql = "UPDATE `settings` SET 
        `allow_reg_msg` = :allow_reg_msg
    WHERE `id` = 1";
    $query = $handler->prepare($sql);
    $query->execute(array(
        ":allow_reg_msg" => $allow_reg_msg
    ));
    Session::flash('edit_site_success', SUCCESS_UPDATE);
    Redirect::to('admin/index.php?page=edit_site');
}

以下是我数据库中的几张图片: image 1, image 2

【问题讨论】:

  • 你能展示一下你得到了什么:var_dump($_POST);
  • @Jeff 我得到“NULL”

标签: php mysql post


【解决方案1】:

我找到了解决方案!它在我的define('BASE_URL', 'https://monkstudio.biz/');

因为我在 .htaccess 中有带有“www”的网站链接,所以在脚本中它没有设置,现在我输入 define('BASE_URL', 'https://www.monkstudio.biz/'); 并且它工作正常!

我很自豪我自己找到了这个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2019-11-02
    • 2016-10-09
    • 1970-01-01
    • 2013-04-13
    相关资源
    最近更新 更多