0

So im working on an app that uses a weather api. In the video course that im using the guy in that course has the exact same code as me but his works and mines doesnt. Im using xampp to test out my php code.

<?php 
    $weather = "";
    $error = "";


    if ($_GET['city']) {

    $urlContents =
    file_get_contents("http://api.openweathermap.org/data/2.5/weather?q=".$_GET['city'].",uk&appid=");

    $weatherArray = json_decode($urlContents, true);

    print_r($weatherArray);
    }

    ?>

The error message is

Notice: Undefined index: city in C:\xampp\htdocs\mobileapp\weather.php on line 6

line 6 is

if ($_GET['city']) {

Also I'm sorry if this has a simple answer im just new to php.

Ezekiel Rivera
  • 71
  • 1
  • 1
  • 5
  • 1
    Instead of doing `if ($_GET['city']) {` (which will generate this notice if it's not set), simply do `if (isset($_GET['city'])) {` – Qirel Jan 10 '17 at 21:41
  • @Qirel is correct, your 'city' parameter hasn't been set. Look at your url and make sure 'city=somecity' is there. – bos570 Jan 10 '17 at 21:45
  • ok the isset worked the error whent away. I didnt realize it was a duplicate question my bad thankyou for your help. Also can you explain what isset is just so i understand the code. – Ezekiel Rivera Jan 10 '17 at 21:55

0 Answers0