I am trying to create a weather website, where the user has 4 options from a drop down menu to select what region they want the weather for, and then from my PHP script I can use file_get_contents() to output the weather once they've selected a region and hit the submit button.
Currently, I have an error displaying: "Notice: Undefined variable: site in ... on line 12". (regarding my cases 'Horfield, 'Thornbury' etc.
I am not sure how to fix this as I have these values in my 'value' field in my tags.
here is my HTML:
<form name="Weather" method="GET" action="<? $_PHP_SELF ?>">
<select id="site" name="site">
<option value="" disabled selected> Select a weather station...</option>
<option value="Horfield" <php if($site == "Horfield") print('selected="selected"'); ?> Horfield (Bristol)</option>
<option value="Thornbury" <php if($site == "Thornbury") print('selected="selected"'); ?>Thornbury (Bristol)</option>
<option value="Glouc" <php if($site == "Gloucestershire") print('selected="selected"'); ?>Gloucestershire</option>
<option value="Newquay" <php if($site == "Newquay") print('selected="selected"'); ?>Newquay (Cornwall)</option>
</select>
<label for="submit"></label>
<input type="submit" id="submit" name="submit">
and here is my PHP file:
<?php
$horfield = file_get_contents("http://www.martynhicks.uk/weather/clientraw.txt");
$thornbury = file_get_contents("http://www.thornburyweather.co.uk/weatherstation/clientraw.txt");
$gloucestershire = file_get_contents("https://www.glosweather.com/clientraw.txt");
$newquay = file_get_contents("http://www.newquayweather.com/clientraw.txt");
if (isset($_GET['site'])){
$site = $_GET['site'];
}
switch ($site) {
case 'Horfield':
echo $horfield;
break;
case 'Thornbury':
echo $thornbury;
break;
case 'Glouc':
echo $gloucestershire;
break;
case 'Newquay':
echo $newquay;
break;
}
?>
I'm sorry if this question seems trivial.
Also, any comments on my lines would be great:
<option value="Horfield" <php if($site == "Horfield") print('selected="selected"'); ?> Horfield (Bristol)</option>
any help is appriciated!
thanks