As mentioned in my previous question I read about cURL and how to work with it. I got the request with the following API: api.openkvk.nl (it’s in Dutch, sadly enough) working:
$get = $_POST['bedrijfsnaam'];
$get = str_replace(" ","%20",$get);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.openkvk.nl/php/SELECT%20*%20FROM%20kvk%20WHERE%20bedrijfsnaam%20=%20'$get'%20LIMIT%201;");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
print("<pre>"); print_r($result); print("</pre>");
$kvks = $result[0]["RESULT"]["ROWS"][0][2];
echo $kvks;
curl_close($ch);
and I got the results back in the following form:
array(array("RESULT"=>array("TYPES"=>array("bigint","varchar","int","int","varchar","varchar","varchar","varchar","varchar","varchar","bigint","varchar","decimal","decimal","date"),"HEADER"=>array("kvk","bedrijfsnaam","kvks","sub","adres","postcode","plaats","type","status","website","vestiging","rechtsvorm","lat_rad","lon_rad","anbi"),"ROWS"=>array(array("526937320000","Unicmedia","52693732","0","Terschellingstraat 12","1825ND","Alkmaar","Hoofdvestiging",NULL,NULL,"22611126",NULL,NULL,NULL,NULL)))))
What I want to do is the following:
Put this values from the database: kvks, adres, postcode and plaats in a form (so that I can edit them).
I don’t know how to do this. Could you give me an explanation?
PS I’m new with API’s so I don’t understand everything yet.
Update:
Their API is returning it as a php string – change the part of your URL which says
/php/to/json/.Then, make it so you have
$result = json_decode(curl_exec($ch), true);Now the array access should work.
To get the value of
kvks, supposing the value you posted is the in$result, you’d use$kvks = $result[0]["RESULT"]["ROWS"][0][2].(It looks like you’re posting the result of a
print_r– try encasing it in<pre>tags when you display it for a much more formatted result)Since you have PHP getting the values, you could simply output an HTML form with them prefilled:
Then, if
$blahisasdf, this would output<input type='text' name='blah' value="asdf">.When you submit it to your
savedata.phpmethod, you’d insert the modified values (now found through$_POST['blah']) into your database however you like.