title: php- curl isn't working
body: <p>Here is my code, I have two cURL statements in the same program. The first one uses $ch and second uses $ch1.  The problem is first one is getting executed and showing the output but second one does nothing.</p>
  
  <pre><code>&lt;?php
  include ('DBconnect.php');
  
  if (isset($_POST['submit'])) {
  $verified = "1";
  $error = array();
  if (empty($_POST['name'])) {
      $error[] = 'I am sure you have a name!';
  }
  else {
      $name = $_POST['name'];
  }
  
  if (empty($_POST['phone'])) {
      $error[] = 'Please enter your phone number with country code';
  }
  else {
      $Phone = $_POST['phone'];
  }
  
  if (empty($_POST['Password'])) {
      $error[] = 'Please choose a password ';
  }
  else {
      $Password = $_POST['Password'];
  }
  
  if (empty($error)) //send to Database if there's no error '
  { // If everything's OK...
  
      // Make sure the phone number is available:
  
      $query_verify_phone = "SELECT * FROM members  WHERE Phone ='$Phone'";
      $result_verify_phone = mysqli_query($dbc, $query_verify_phone);
      if (!$result_verify_phone) { //if the Query Failed ,similar to if($result_verify_phone==false)
          echo ' Database Error Occured ';
      }
  
      if (mysqli_num_rows($result_verify_phone) == 0) { // IF no previous user is using this phone number.
          $query_insert_user = "INSERT INTO `members` ( `Name`, `Phone`, `Password`, `Verified`) VALUES ( '$name', '$Phone', '$Password', '$verified')";
          $result_insert_user = mysqli_query($dbc, $query_insert_user);
          if (!$result_insert_user) {
              echo 'Query Failed ';
          }
  
          if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.
              $customerToken = "TOKEN HERE";
              $clientTransactionId = rand(55555, 77777);
              $duration = "180";
              $countryCode = "91";
              $z2vToken = "TOKEN HERE";
              $postData = array(
                  'customerToken' =&gt; $customerToken,
                  'clientTransactionId' =&gt; $clientTransactionId,
                  'callerid' =&gt; $Phone,
                  'duration' =&gt; $duration,
                  'countryCode' =&gt; $countryCode,
                  'z2vToken' =&gt; $z2vToken,
              );
  
              // create post body
  
              $post_body = '';
              foreach($postData as $key =&gt; $value) {
                  $post_body.= urlencode($key) . '=' . urlencode($value) . '&amp;';
              }
  
              $post_body = rtrim($post_body, '&amp;');
  
              // Initialize CURL data to send via POST to the API
              // FIRST ONE CURL REQUEST- WORKING
  
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, "http://www.zipdial.com/z2v/startTransaction.action");
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($ch, CURLOPT_POST, 1);
              curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);
  
              // Execute CURL command and return into variable ch
  
              $string = curl_exec($ch);
              curl_close($ch);
              $json = json_decode($string);
  
              // now the json has been decoded
              // echo "Please do a missed call  on: ";
              // echo "&lt;img src=' ".$json-&gt;img."'&gt;";
  
              $pf = 'fl' . uniqid();
              $un = uniqid($pf);
              $fpl = 'img' . $un . '.png';
              file_put_contents($fpl, file_get_contents($json-&gt;img));
  </code></pre>
  
  <p>Everything above goes fine but the second curl request is not working:</p>
  
  <pre><code>            // EVERYTHING ABOVE GOES FINE. BELOW IS SECOND REQUEST- NOT WORKING
  
              $url = "https://api.idolondemand.com/1/api/sync/ocrdocument/v1";
              $post = array(
                  'apikey' =&gt; "MY KEY HERE",
                  'url' =&gt; "http://site.ext/users/$fpl",
                  'mode' =&gt; "document_photo"
              );
              $ch1 = curl_init();
              curl_setopt($ch1, CURLOPT_URL, $url);
              curl_setopt($ch1, CURLOPT_POST, 1);
              curl_setopt($ch1, CURLOPT_POSTFIELDS, $post);
              curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
              $ocr = curl_exec($ch1);
              $jsonocr = json_decode($ocr, true);
              $textblock = $jsonocr['text'][0];
              echo '&lt;div class="success"&gt;Please give a missed call to ' . $textblock['text'] . ' from your registered phone number to activate account. &lt;/div&gt;';
              curl_close($ch1);
          }
          else { // If it did not run OK.
              echo '&lt;div class="errormsgbox"&gt;You could not be registered due to a system  error. We apologize for any inconvenience.&lt;/div&gt;';
          }
      }
      else { // The phone number is not available.
          echo '&lt;div class="errormsgbox" &gt;That phone number has already been registered. &lt;/div&gt;';
      }
  }
  else { //If the "error" array contains error msg , display them
      echo '&lt;div class="errormsgbox"&gt; &lt;ol&gt;';
      foreach($error as $key =&gt; $values) {
          echo ' &lt;li&gt;' . $values . '&lt;/li&gt;';
      }
  
      echo '&lt;/ol&gt;&lt;/div&gt;';
  }
  
  mysqli_close($dbc); //Close the DB Connection
  } // End of the main Submit conditional.
  
  ?&gt;
  </code></pre>
  
  <p>I can  make request to second curl request manually from my browser and it works but it isn't working here. What's wrong?</p>