PHP在每个月底自动提交表单

时间:2018-09-24 06:23:20

标签: php

我有一个带有隐藏字段的表单,希望在月底的每个月末自动提交(例如:9月30日,23:55),而无需访问页面并按提交按钮。我如何实现这一目标?现在,仅当我访问该页面并按“保存”按钮时,我的表单才提交。

我的php代码:

if(isset($_POST['btnSavee'])){
        $product_name = $_POST['product_name'];
        $percentage = $_POST['percentage'];
        $qty_reqliz = $_POST['qty_reqliz'];
        $trg_cantit = $_POST['trg_cantit'];
        $trg_val_realiz = $_POST['trg_val_realiz'];
        $agent_name = $_POST['agent_name'];
        $agent_id = $_POST['agent_id'];
        $the_bonus = $_POST['the_bonus'];
        $realizat_total = $_POST['realizat_total'];
        $prod_over_60 = $_POST['prod_over_60'];

        // create array variable to handle error
        $error = array();

        for($i=0;$i<count($product_name);$i++) {
            if($product_name[$i]!="" && $percentage[$i]!="") {

                $sql_queryes = "INSERT INTO tbl_stats_history (Product_name, Percentage, Qty_realiz, Trg_cantit, Trg_val_realiz, Ag_name, Ag_id)
                            VALUES(?, ?, ?, ?, ?, ?, ?)";


                $stmtes = $connect->stmt_init();
                if($stmtes->prepare($sql_queryes)) {
                    $stmtes->bind_param('sssssss', 
                        $product_name[$i], 
                        $percentage[$i],
                        $qty_reqliz[$i],
                        $trg_cantit[$i],
                        $trg_val_realiz[$i],
                        $agent_name[$i],
                        $agent_id[$i]
                    );
                    // Execute query
                    $stmtes->execute();
                    // store result 
                    $resultest = $stmtes->store_result();
                    $stmtes->close();
                }

                if($resultest){
                    $error['update_data'] = " <h4><div class='alert alert-success'>
                                                    Date salvate cu succes! 
                                                    </div>
                                              </h4>";
                    }else{
                        $error['update_data'] = " <span class='label label-danger'>".$stmtes->error."</span>";
                    }   
            }
        }

        $sql_querye = "INSERT INTO tbl_stats_bonus (Bonus, Realiz_total, Prod_over_60, Age_id)
                            VALUES(?, ?, ?, ?)";


                $stmts = $connect->stmt_init();
                if($stmts->prepare($sql_querye)) {
                    $stmts->bind_param('ssss', 
                        $the_bonus, 
                        $realizat_total,
                        $prod_over_60,
                        $ID
                    );
                    // Execute query
                    $stmts->execute();
                    // store result 
                    $resulte = $stmts->store_result();
                    $stmts->close();
                }
    }

我的html表单(带有提交按钮):

<form method="post">
  <input class="form-control" name="product_name[]" value="Prod1" type="hidden" />
  <input class="form-control" name="product_name[]" value="Prod2" type="hidden" />
  <input class="form-control" name="percentage[]" value="50%" type="hidden" />
  <input class="form-control" name="percentage[]" value="12%" type="hidden" />
  <button class="btn bg-green btn-primary waves-effect pull-right" type="submit" name="btnSavee">Save</button></form>

1 个答案:

答案 0 :(得分:2)

一段时间后,您需要学习cron作业才能在php中自动工作。

您还可以看到this question