Jump to content

How can I make 2 form actions with 1 button


PNewCode
 Share

Recommended Posts

Hello,

I've searched around but I think I must not know how to phrase the question because I cannot find a solution. 

OBJECTIVE: I have a page where an image that acts like a button sends the information to another php page. And that page that gets the information is inserted to a database.
I need to have this one button send it to TWO php pages, as each of them perform the same function, but different databases.

Summary of what I am wanting to do: Make this one button post to 2 different php files.

Here is my code that works perfectly for just one php file:
 

echo  " <form class='leftf' action='process2.php' method='post'><input type='hidden' name='actionType' value='order_change'><input type='hidden' name='update_id' value='$updateID'><input type='hidden' name='current_postion' value='$order_change'><input type='hidden' name='order_change' value='$order_change_up' required><button type='submit'><img src='up.jpg'></button></form>";

 

Link to comment
Share on other sites

Example of form and writing its form data to two tables in different databases

<?php

$con = <your db connection code> ;

if ($_SERVER['REQUEST_METHOD']=='POST')  {
    
    $stmt1 = $con->prepare("INSERT INTO database1.mytable(col1, col2, col3) VALUES (?,?,?)");        // insert into table i database1
    $stmt2 = $con->prepare("INSERT INTO database2.mytable(col1, col2, col3) VALUES (?,?,?)");        // insert into table i database2
    $stmt1->execute([ $_POST['val1'],$_POST['val2'],$_POST['val3'] ]);
    $stmt2->execute([ $_POST['val1'],$_POST['val2'],$_POST['val3'] ]);
    
}

?>

<form method='post'>
    Value 1 <input name='val1'>
    Value 2 <input name='val2'>
    Value 3 <input name='val3'>
    <input type='submit>'
</form>
Link to comment
Share on other sites

The reason for having 2 pages is to view both databases. Yes they are on the same server.

One page displays one database, the other page displays content on the other database.

One is current, the other is a backup

Thank you for the example of the script I'll work with that to see what I can do :)

Link to comment
Share on other sites

the processing of the submitted post method form data should have nothing directly to do with the display of any data.

you should -

  1. display the form
  2. when the form is submitted, detect if a post method form has been submitted
  3. trim, then validate the form data, storing any user/validation errors in an array using the field name as the array index
  4. if there are no user/validation errors, use the form data (which could result in more user errors, such as for duplicate or out of range values)
  5. if here are no errors at this point, redirect to the exact same url of the current page to cause a get request for the page
  6. to display a one-time success message, store it in a session variable, then test, display, and clear that session variable at the appropriate location in the html document
  7. at this point, you would get any data needed to display the current page, then output it in the html document. if you want the user to be able to go to different page(s), that queries for and displays other data, provide navigation link(s) to do so.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.