PNewCode Posted November 24, 2022 Share Posted November 24, 2022 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/ Share on other sites More sharing options...
Barand Posted November 24, 2022 Share Posted November 24, 2022 Why submit to 2 pages? Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602931 Share on other sites More sharing options...
PNewCode Posted November 24, 2022 Author Share Posted November 24, 2022 One has entries deleted from it, the other does not and serves as a backup Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602932 Share on other sites More sharing options...
Barand Posted November 24, 2022 Share Posted November 24, 2022 OK. But, again, why do you need two pages? Are both databases on the same server? (Even if they aren't it just means you need two connections) Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602933 Share on other sites More sharing options...
Barand Posted November 24, 2022 Share Posted November 24, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602935 Share on other sites More sharing options...
PNewCode Posted November 25, 2022 Author Share Posted November 25, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602947 Share on other sites More sharing options...
Barand Posted November 25, 2022 Share Posted November 25, 2022 Why duplicate all the code when the only thing that needs to change is the name of the database in the query? Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602948 Share on other sites More sharing options...
mac_gyver Posted November 25, 2022 Share Posted November 25, 2022 the processing of the submitted post method form data should have nothing directly to do with the display of any data. you should - display the form when the form is submitted, detect if a post method form has been submitted trim, then validate the form data, storing any user/validation errors in an array using the field name as the array index 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) 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 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/315580-how-can-i-make-2-form-actions-with-1-button/#findComment-1602949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.