0

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 can use `PHP cronjob` for this.But it will submit form without any data and that is useless. So i am unable to understand why you want that? – Alive to die - Anant Sep 24 '18 at 06:25
  • create a cron job in php – Jignesh Joisar Sep 24 '18 at 06:25
  • Possible duplicate of :-[How to create cron job using PHP?](https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php) – Alive to die - Anant Sep 24 '18 at 06:29
  • You need to be learn cron job for automatic work in php after some time. You can see hare https://www.cloudways.com/blog/schedule-cron-jobs-in-php/ – Suman Sep 24 '18 at 06:31
  • @lulian You can save the data into database on each change using ajax. Now set a column lets sat is_submitted, which would be false by default. Now each and every updated field you will have in your database. With the help of cron job just set the is_submitted value as true. Please let me know if any doubt. – Brn.Rajoriya Sep 24 '18 at 06:33
  • 1
    Possible duplicate of [How to create cron job using PHP?](https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php) – fabrik Sep 24 '18 at 06:38
  • Possible duplicate of [PHP: running scheduled jobs (cron jobs)](https://stackoverflow.com/questions/120228/php-running-scheduled-jobs-cron-jobs) – Tom Udding Sep 24 '18 at 07:09
  • i already know cron job, but as Alive to Die said is useless, because the form it will send empty. i need this job because that hapend in every month and i am not at computer to save the data – Iulian Nistor Sep 24 '18 at 07:35
  • can somebody help me? – Iulian Nistor Sep 26 '18 at 05:47

1 Answers1

2

You need to be learn cron job for automatic work in php after some time.

you can see this question also..