title: how to auto fill and submit html form with curl
body: <p>I want to auto fill an html form and submit the form and display the result. I used below code got from <a href="http://www.html-form-guide.com/php-form/php-form-submit.html" rel="nofollow">here</a>.</p>
  
  <pre><code>&lt;?php
  //create array of data to be posted
  $post_data['email'] = 'myemail';
  $post_data['pass'] = 'mypassword';
  
  //traverse array and prepare data for posting (key1=value1)
  foreach ( $post_data as $key =&gt; $value) {
      $post_items[] = $key . '=' . $value;
  }
  
  //create the final string to be posted using implode()
  $post_string = implode ('&amp;', $post_items);
  
  //create cURL connection
  $curl_connection = 
    curl_init('http://m.facebook.com/');
  
  //set options
  curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($curl_connection, CURLOPT_USERAGENT, 
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
  curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
  
  //set data to be posted
  curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
  //perform our request
  $result = curl_exec($curl_connection);
  
  print $result;
  //show information regarding the request
  echo curl_errno($curl_connection) . '-' . 
                  curl_error($curl_connection);
  
  //close the connection
  curl_close($curl_connection);
  ?&gt;
  </code></pre>
  
  <p>and I used Facebook mobile site and gmail to test this code.</p>
  
  <p>I placed the url of login page of those sites in curl_init function, gave the value of name attributes of username and password fields of login page into keys of $post_data array and  saved this code as my.php file and placed it in xampp htdocs directory in local machine. </p>
  
  <p>when I browse the my.php, it displays the login page with username field is filled and password field is not filled. according to the code, The expected result is, It should return the successfully logged page because I have provided the correct username and password. also the curl_errno returns 0. that means no error occurred. Then why I can't get the expected result? and Why password field is not filled although username field is filled?</p>