简体   繁体   中英

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. How i achieve this? Now my form is submitting only if i access the page and press the "Save" button.

My php code:

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):

 <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.

you can see this question also..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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