Home > Blockchain >  Add value for submit of a form
Add value for submit of a form

Time:12-25

Every time someone submits my form I want to add 1 to a value (MySQL). Then I want to include the number of submission in my PDF. Like: submissions: 002 ---> submission of form ---> adding 1 to the value---> submissions: 003 ---> print the number of submissions on the pdf.

<script>          
    // Function to GeneratePdf
    function GeneratePdf() {
        var element = document.getElementById('message');
        var element = document.getElementById('name');
        html2pdf(element);
    }
</script>

CodePudding user response:

Form submission

I presume you have a form and it can be submitted. If that's not the case, then I will edit this section.

Server-side

You will need to use PDO in order to get the number of submissions. Store the new submission, using PDO again. Increment the value you just had

Send out the value to the client

And then increment a counter and make sure that you set document.getElementById('message').innerText = 'submissions: ' yournumber;

CodePudding user response:

Javascript

});
<script>
    function GeneratePdf() {
        var element = document.getElementById('message');
        var element = document.getElementById('name');
        $.ajax({
            type: 'POST',
            url: 'update_submission.php',
            data:{form_id:'1'} //Add form id if you have one
            processData: false,
            contentType: false
        }).done(function(data) {
           console.log(data);
            html2pdf(element);
        });
    }
</script>

I've created this dummy table just to explain my update query, you can change the query as per your table structure.

CREATE TABLE form_submission(
    id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    submits INT(10) DEFAULT 0
);

update_submission.php

$form_id = $_POST['form_id'];

$sql = "mysql_query("
    UPDATE form_submission 
    SET submits = submits   1
    WHERE id = '".$form_id."'
");";

mysql_query($sql); 
  • Related