Andre J
Andre J

Reputation: 227

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?

Upvotes: 1

Views: 3064

Answers (3)

Email
Email

Reputation: 2425

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

Upvotes: 1

linepogl
linepogl

Reputation: 9335

Create a new php file, like this:

<?php

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

?>

Upvotes: 4

spamoom
spamoom

Reputation: 464

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 :)

Upvotes: 0

Related Questions