Php 如何将表单提交到两个不同的页面

Php 如何将表单提交到两个不同的页面,php,mailman,Php,Mailman,我正在为邮件列表创建一个注册表单。提交表单后,我想注册数据库中的所有数据,然后将数据“重新提交”到另一个页面,以便在邮件列表中注册用户 我知道如何在数据库中注册所有数据,但是我不知道如何将数据“重新提交”到另一个页面 为什么有必要?这是必要的,因为我使用GNU邮递员作为邮件列表系统。该软件只存储姓名、电子邮件和密码,因此我无法创建带有自定义字段的注册表,如“国家”、“城市”和“性别”。您可以编写一个PHP脚本,用于编写HTTP请求并将其发送到第二个脚本 /* get your

我正在为邮件列表创建一个注册表单。提交表单后,我想注册数据库中的所有数据,然后将数据“重新提交”到另一个页面,以便在邮件列表中注册用户

我知道如何在数据库中注册所有数据,但是我不知道如何将数据“重新提交”到另一个页面


为什么有必要?这是必要的,因为我使用GNU邮递员作为邮件列表系统。该软件只存储姓名、电子邮件和密码,因此我无法创建带有自定义字段的注册表,如“国家”、“城市”和“性别”。

您可以编写一个PHP脚本,用于编写HTTP请求并将其发送到第二个脚本

    /*
      get your data from db and put it into an associated array:

       $post_array['name] = $row['name'];
       $post_array['country] = $row['country'];

       ..and so on

    */

   //serialize the post array into a string 
   foreach($post_array as $key=>$value) { $fields .= $key.'='.$value.'&'; }        
   rtrim($fields,'&');

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL, 'http://domain.com/script.php');
    curl_setopt($ch,CURLOPT_POST,count($post_array);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);


    $response= curl_exec($ch); //submit it..
    $httpCode= curl_getinfo($ch, CURLINFO_HTTP_CODE); //use $httpCode to figure out if it was successful (200) or not.

您可以编写一个PHP脚本,用于编写HTTP请求并将其发送到第二个脚本

    /*
      get your data from db and put it into an associated array:

       $post_array['name] = $row['name'];
       $post_array['country] = $row['country'];

       ..and so on

    */

   //serialize the post array into a string 
   foreach($post_array as $key=>$value) { $fields .= $key.'='.$value.'&'; }        
   rtrim($fields,'&');

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL, 'http://domain.com/script.php');
    curl_setopt($ch,CURLOPT_POST,count($post_array);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);


    $response= curl_exec($ch); //submit it..
    $httpCode= curl_getinfo($ch, CURLINFO_HTTP_CODE); //use $httpCode to figure out if it was successful (200) or not.
我的简单尝试。 表格提交的第一页

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post">
<input type="text"  name="email"/>
<input type="text"  name="name"/>
<input type="submit" value="registration" name="register" />
</form>

<?php 

//connection with database.
$conn=mysql_connect("localhost","root","");

mysql_select_db("test");

//check if form submitted
  if(isset($_POST['register']))
  {
  $result=mysql_query("INSERT INTO testdata(name,email)   values('".$_POST['name']."','".$_POST['email']."')") or die(mysql_error()); 

 if(mysql_affected_rows($conn)>0)
 {
  echo "Done";

 $url = 'http://localhost/TESTCODE/get-post.php';

 $fields = array(
        'name'=>urlencode($_POST['name']),
        'email'=>urlencode($_POST['email'])           
       );


   /* on my install of PHP 5.3, http_build_query() seems to use &amp; as the default  separator.  */



   $fields_string=http_build_query($fields);



  //open connection
  $ch = curl_init();


  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL,$url);

 curl_setopt($ch,CURLOPT_POST,count($fields));

  curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

 //execute post

 $result = curl_exec($ch);

 //close connection

 curl_close($ch);

}
 }
 ?>

 </body>
 </html>

无标题文件
我的简单尝试。
表格提交的第一页

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post">
<input type="text"  name="email"/>
<input type="text"  name="name"/>
<input type="submit" value="registration" name="register" />
</form>

<?php 

//connection with database.
$conn=mysql_connect("localhost","root","");

mysql_select_db("test");

//check if form submitted
  if(isset($_POST['register']))
  {
  $result=mysql_query("INSERT INTO testdata(name,email)   values('".$_POST['name']."','".$_POST['email']."')") or die(mysql_error()); 

 if(mysql_affected_rows($conn)>0)
 {
  echo "Done";

 $url = 'http://localhost/TESTCODE/get-post.php';

 $fields = array(
        'name'=>urlencode($_POST['name']),
        'email'=>urlencode($_POST['email'])           
       );


   /* on my install of PHP 5.3, http_build_query() seems to use &amp; as the default  separator.  */



   $fields_string=http_build_query($fields);



  //open connection
  $ch = curl_init();


  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL,$url);

 curl_setopt($ch,CURLOPT_POST,count($fields));

  curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

 //execute post

 $result = curl_exec($ch);

 //close connection

 curl_close($ch);

}
 }
 ?>

 </body>
 </html>

无标题文件

Curl是一个很好的解决方案,通常我会这样做。不过,对于技术含量较低的解决方案,使用Ajax请求提交给mailman,并在成功回调时提交主表单。但是如何做到呢?你能给我举个例子吗?迈克尔,你是自由职业者吗?你能分享一段代码来解释它吗?我会很高兴付钱给你提供这个代码。+1的旋度。。。虽然您也可以使用命令行实用程序将订阅者添加到邮件列表(请参阅),而不是重新发布数据。Curl是一个很好的解决方案,通常我会这样做。不过,对于技术含量较低的解决方案,使用Ajax请求提交给mailman,并在成功回调时提交主表单。但是如何做到呢?你能给我举个例子吗?迈克尔,你是自由职业者吗?你能分享一段代码来解释它吗?我会很高兴付钱给你提供这个代码。+1的旋度。。。尽管您也可以使用命令行实用程序将订阅者添加到邮件列表(请参阅),而不是重新发布数据。