【问题标题】:Why isn't PHP sending POST request?为什么 PHP 不发送 POST 请求?
【发布时间】:2015-09-30 10:12:34
【问题描述】:

我尝试提交表单,但它没有发送我的表单。如果我尝试打印 POST 数组,它只是空的。

这是我的表格:

<?php 
print_r($_POST);
require('includes/config.php');
require('includes/auth_admin.php');
$title = "New Block Day";
require ('includes/header.php');

//if form has been submitted process it
if(isset($_POST['submit'])){

    if(empty($_POST['name'])){
    $error[] = 'Please Enter a name.';
    }

    $date = $_POST['date'];
    $result = mysqli_query($con, "select name from official_holiday where date = $date");
    while ($row = mysqli_fetch_assoc($result)) {
    $check[] = $row;        
    }


    if(empty($_POST['date'])){
    $error[] = 'Please Enter a date.';
    }elseif(!empty($_POST['date'])){
    $error[] = 'Already block date on that day.';
    }

    $new_date = $_POST['date'];
    $new_name = $_POST['name'];


    $query = sprintf("INSERT INTO official_holiday (name, date) VALUES ('%s', '%s')",
    mysql_real_escape_string($new_name),
    mysql_real_escape_string($new_date));


    $result = mysqli_query($con, $query);


            header("Location:new_block.php?id=$id&changes=successful");

    }else{
    //header('0');
        //exit;
    }       
?>
            <div class="container">
        <div class="row">
            <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
            <form action="new_block.php" method="post" role="form" >
            <h3><?php echo $title ?></h3>
            <p><a href='block_days.php'>Back</a></p>
            <?php
            if(isset($_GET['changes']) && $_GET['changes'] = 'successful'){
            echo '<h4>Changes successful.</h4>';
            }
            ?>
            <hr>
            <label for="name">Name</label>
                <div class="form-group">
                    <input type="text" required name="name" id="name" class="form-control" value="<?php if(isset($error)){ echo $_POST['name']; } ?>" tabindex="3">
            </div>

            <div class="form-group">
                    <label for="datepicker">Date</label>
                        <div class="input-group input-append date">
                            <input type="text" class="form-control" id="datepicker" name="date" placeholder="Date" value="<?php if(isset($error)){ echo $_POST['date']; } ?>">
                            <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar">
                       </div>
                    </div>

            <div class="form-group">
                    <input type="submit" name="submit" id="name" value="submit" class="btn btn-info btn-block" tabindex="5">
            </div>
            </form>
        </div>
    </div>
</div>

<?php
require('includes/footer.php'); 
?>

为什么 PHP 不发送任何内容?

编辑:我添加了完整的代码,但我可以添加的内容不多。

【问题讨论】:

  • 怎么知道post数组是空的?你在看 $_GET
  • @e4c5,他一定是在new_block.php页面中查看$_POST.. ;-)
  • 你能给我们看看你的 new_block.php 页面吗?
  • 我现在添加了完整的代码
  • 如果您在同一页面上检查isset($_POST['submit'])&lt;form action="new_block.php" 在那里做什么?

标签: php forms post


【解决方案1】:

请先评论您的重定向:

// header("Location:..")

【讨论】:

  • 这不是我想要的。当我发送表格并检查它是否有错误时,应该会出现该消息。所以 MySQL 代码也应该被执行,但它没有进入我的 if: if(isset($_POST['submit']))
猜你喜欢
  • 1970-01-01
  • 2015-08-06
  • 2021-11-16
  • 1970-01-01
  • 2017-07-13
  • 2014-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多