简体   繁体   中英

How can I submit one HTML form to multiple php files?

I have an HTML form that I need to submit to a php file that adds it to a database, as well as to an existing php file that adds it to an online CSV file.

Any ideas?

Create a new php file, like this:

<?php

  include('form_handler_1.php');
  include('form_handler_2.php');

?>

Use the $_POST or $_GET array to call the other file.

For example after your mysql take the $_POST and submit them with $_GET to the next file.

file 1:

$name = $_POST['name'];
$address = $_POST['address'];
## put here your mysql query and connect
## end query

##submit the values as variables to the other script

$url = "http://www.mysite.com/seconfile.php?name=".$name."&address=".$address;
file_get_contents ($url);

second file:

$name = $_GET['name'];

Curl would also fit or fopen or file.

You can do that endlessly and shorten the coding with using a foreach loop through the array creating the urls.

coded but not tested

You could send it to your database php file, and then use curl to send the request to the second php file.

See this link for instructions on how to use curl :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM