Im using POST method to insert some data to db on my server.This is my connection.php file that is stored in my http://www.url.com/public_html.
The value you've specified for $servername is not a host name but rather a URL, or resource name. The host name would be just www.url.com.
$servername
www.url.com
Of course, as you've already discovered, localhost is the correct host name if the client and server reside on the same box.
localhost