开发者

How to submit the form to two different pages

开发者 https://www.devze.com 2023-03-07 12:58 出处:网络
I\'m creating a register form for a mail list. After submit the form, I\'d like to register all data in the database and then \"re-submit\" the data to another page to register the 开发者_运维技巧user

I'm creating a register form for a mail list. After submit the form, I'd like to register all data in the database and then "re-submit" the data to another page to register the 开发者_运维技巧user on the mail list.

I know how to register all data in the database, however I don't know how to "re-submit" the data to another page.

Why it's necessary? It's necessary, because I'm using the GNU Mailman as mail list system. This software only store name, e-mail and password, then I can't create a register form with custom fields, like "Country", "City" and "Gender".


You could write a PHP script that uses CURL to craft an HTTP request and send it off to the 2nd script

    /*
      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.


my simple try. first page where form submit

<!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>

and 2nd page get-post.php where again i submitted form via curl

 <?php
 $conn=mysql_connect("localhost","root","");
mysql_select_db("test");
$result=mysql_query("INSERT INTO testdata(name,email)     values('".$_POST['name']."','".$_POST['email']."')") or die(mysql_error()); 
  ?>

i just did it for a simple checking.you should modify as you need. here i inserted data two times in two different page

0

精彩评论

暂无评论...
验证码 换一张
取 消