Jump to content

Who Can Help With My Error?


nachtegaal9999

Recommended Posts

Hi,I used the next Curl script at my siteand get an error on line 21 Error message : Notice: Undefined index: postcode in /home/a5532984/public_html/coordinaten opvragen met CURL.php on line 21Translation zipcode = postcodeThanks in advanceSimon BuijsNetherlandsUsed script <?php$postcode='1628DC';ini_set('display_errors',1);error_reporting(E_ALL);function getpostcode($postcode) { $url = 'http://maps.google.com/maps/geo?output=json&oe=utf-8&q='.$postcode.'%20netherlands'; $startat = '"coordinates": [ '; $stopat = ", 0 ]"; $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $start = curl_exec($ch); curl_close($ch); $exploded = explode($startat,$start); $exploded = explode($stopat,$exploded[1]); $result = str_replace('<br />','',nl2br($exploded[0])); return $result;}if (getpostcode($_GET['postcode'])!=''){echo "The accordinates are: ".getpostcode($_GET['postcode']);}else{echo 'Zip code is not correct';}?>

Link to comment
Share on other sites

Change this line:if (getpostcode($_GET['postcode'])!=''){to this:if (!empty($_GET['postcode']) && getpostcode($_GET['postcode'])!=''){
Hi, The error has gone, but gives the result that the zip code (postcode) is wrong= error resultI know for sure that the zipcode is 100% correct , declined at line 2Simon
Link to comment
Share on other sites

It's not checking the postcode declared on line 2, it's checking for a postcode in $_GET. e.g.:page.php?postcode=abc123
I understand that the code checks $_GET. e.g.:Does it means that my variable at line 2 is not valid or emptyExact as you told the page should be page.php?postcode=abc123 (1628DC)But how manege i to change the script that it receives the correct zip code.Best regardsSimonHoorn, Netherlands
Link to comment
Share on other sites

Have line 2 get the postcode.$postcode = !empty($_GET['postcode']) ? $_GET['postcode'] : '';Then change the if statement on the bottom to use that instead:

if (getpostcode($postcode)!=''){echo "The accordinates are: ".getpostcode($postcode);}

Since you're using CURL to send that request out, it will probably be better to run the getpostcode function once and save the return value to a variable, and then use that in the if statement instead. That way you don't have to send 2 requests out.

Link to comment
Share on other sites

Hi,I want to thank you all , i've made the latest amend in the script and have tested it works fine.I'll hope sombody has some benifit of it.Thanks it is great.GreetingsSimon Netherlands<?php$postcode='1628DC'; ini_set('display_errors',1);error_reporting(E_ALL);function getpostcode($postcode) { $url = 'http://maps.google.com/maps/geo?output=json&oe=utf-8&q='.$postcode.'%20netherlands'; $startat = '"coordinates": [ '; $stopat = ", 0 ]"; $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $start = curl_exec($ch); curl_close($ch); $exploded = explode($startat,$start); $exploded = explode($stopat,$exploded[1]); $result = str_replace('<br />','',nl2br($exploded[0])); return $result;}if (getpostcode($postcode)!=''){echo 'The coordinates are: '.getpostcode($postcode);} else{echo 'The Zipcode is not correct';}?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...