tags:

views:

17

answers:

1

I am using PHP's Curl functions to post data to the web server from my local machine. the code that i am using,

  $c = curl_init();
  curl_setopt($c, CURLOPT_URL, $url);
  curl_setopt($c, CURLOPT_RETURNTRANSFER,true);
  curl_setopt($c, CURLOPT_POST, true);
  curl_setopt($c, CURLOPT_POSTFIELDS, $data);
  $result=curl_exec ($c);
  if(curl_exec($c) === false)
  {
    echo "ok";
  }
  else
  {
    echo "error";
  }

  curl_close ($c);

this is a basic code that i am using, but i am not able to catch any error..like if in case of 404,500 or network failure how will i get to know that data was not posted to server.

+3  A: 

You can use the curl_error() function to know if there was some error, example:

if(curl_errno($c))
{
    echo 'error:' . curl_error($c);
}

See the description of curl error codes here

Sarfraz
@Sarfraz it is catching the error, and first of all thanks!
Harish Kurup
@Harish Kurup: Welcome...
Sarfraz