简体   繁体   English

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

[英]PHP submit a form at every end of month automatically

I have a form with hidden fields that i whant to submit every end of month (exemple: 30 September at 23:55) automatically without accessing the page and press a submit button. 我有一个带有隐藏字段的表单,希望在每个月末(例如:9月30日23:55)自动提交,而无需访问该页面并按提交按钮。 How i achieve this? 我如何实现这一目标? Now my form is submitting only if i access the page and press the "Save" button. 现在,仅当我访问页面并按“保存”按钮时,我的表单才提交。

My php code: 我的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();
                }
    }

And my html form (it is with submit button): 而我的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> 

You need to be learn cron job for automatic work in php after some time. 一段时间后,您需要学习cron才能在php中自动工作。

you can see this question also.. 您也可以看到这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM