user5397448 user5397448 - 2 months ago 4
PHP Question

how to post the value in url using PHP

I am creating a web service. I have tried to write an URL but its throwing error. I am not getting where I am going wrong. I want to pass these variable values in url and depending on this i want to call the web service

<?php
if($_POST["occupation"] == '1'){
$occupation = 'Salaried';
}
else{
$occupation = 'Self+Employed';
}

$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?interestRateType='.$_POST["interestRateType"]'.&occupation='.$_POST["occupation"].'&offeringTypeId='.$_POST["offeringID"].'&city='.$_POST["city"].'&loanAmt='.$_POST["loanAmt"].'&age='.$_POST["age"];
echo $url;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
$json = json_decode($result, true);

//print_r($json);
//echo $json['resultList']['interestRateMin'];
$json_array = $json['resultList'];

print_r($json_array);

?>

Answer

Copy this because there is some ' and . error

$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?
        interestRateType='.$_POST["interestRateType"].'&
        occupation='.$_POST["occupation"].'&
        offeringTypeId='.$_POST["offeringID"].'&
        city='.$_POST["city"].'&
        loanAmt='.$_POST["loanAmt"].'&
        age='.$_POST["age"];