How to use 2 submit separately in html?

0

Hello, I'm doing an upload system, but when I submit in the following code both exchange the value of the ID variable.

My idea is to change the value of the ID so that the folder that will be uploaded changes, as can be seen in the 1st echo, while in the 2nd echo it shows the upload button itself.

I want only the 1st echo to change the value of the ID when I use submit.

echo "<form action='' method='POST' enctype='multipart/form-data'>
    <input type='text' name='ID' id='ID' placeholder='INSIRA O ID'>
    <input type='submit' value='confirmar' id='ID'>";
    $ID = $_POST['ID'];
    echo "<form action='' method='POST' enctype='multipart/form-data'>
    <input type='file' name='allfiles' />
    <input type='submit'/>
    </form>";
    
asked by anonymous 01.09.2017 / 14:51

2 answers

1

I have separated by 2% with% different. I think this solves your problem:

    echo 
    "<form action='' method='POST' enctype='multipart/form-data'>
        <input type='text' name='ID' id='ID' placeholder='INSIRA O ID'>
        <input type='submit' value='confirmar' id='ID'>   
    </form>";
    $ID = $_POST['ID'];
    echo 
    "<form action='' method='POST' enctype='multipart/form-data'>
        <input type='hidden' name='ID' value='{$ID}'>
        <input type='file' name='allfiles' />
        <input type='submit'/>
    </form>";
    
01.09.2017 / 15:36
0

You need to close the first </form> because the way this your code everything is a single form, and when clicking on any submit all data is submitted.

When you click on the confirm of the 1st form it generates a POST, we will call it POST_1, and when the 2nd form is submitted, we will call POST_2, POST_1 will no longer exist and your data will not either, what exists now is or POST_2. It is as if you refresh the page after sending the form, ie the memory is recreated from scratch.

What you can do: Save somewhere (BD or SESSION) the id information that comes in POST_1 and retrieve it for use in POST_2.

Send the posts to different php pages, which would need to save the id anyway.

Send everything to a single form.

    
01.09.2017 / 16:02