Click here to Skip to main content
15,886,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys, I'm new in php and javascript and I have problem. So I have table and each row I have col of inpute type date and inpute type file and input type button, when I chosse my date and also the the file and click in the button it must save my date in databse mysql and the file in a directory at the same time. so if I pick the first row it works perfectly but the next rows it's not working.

What I have tried:

here is my code :

my html code :
<pre><pre>html += '<tr><td><input type="date" id="Date_Vendu" name="Date_Vendu[]" 
                   class="form-control" value="'+data[count].datev+'" /></td>';
html += '<td><input type="file" id="file" name="file[]" /><input type="hidden" 
         id="hidden_id" name="hidden_id[]" value="'+data[count].id+'" /></td>';
html += '<td><input type="button" value="Enregistrer" class="but_upload form-control" /> 
         </td></tr>


my javascript code:
$(document).on('click', '.but_upload', function() {

        var fd = new FormData();
        var files = $('#file')[0].files[0];
        fd.append('file', files);

        var ID = $('#hidden_id').val();
        fd.append('id', ID);

        var date = $('#Date_Vendu').val();
        fd.append('datev',date);

        var index = $('#mytable').closest('tr').find('td');
        var txtvalue = $('#mytable').closest("tr").find('td:eq(5)').val()

        $.ajax({
            url: 'updateSuivi.php',
            type: 'post',
            data: fd,
            contentType: false,
            processData: false,
            success: function(response){
                if(response != 0){
                    alert('file uploaded'+' '+ID+' '+date);location.reload();
                }
                else{
                    alert('file not uploaded'+' '+txtvalue);location.reload();
                }
            },
        });
    });


and thank you in advance.
Posted
Comments
Richard Deeming 16-Dec-21 11:34am    
IDs in an HTML document must be unique. If you use the same ID for the elements in every row, then your document is invalid. Accessing the element by ID will only return one of the elements.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900