Click here to Skip to main content
11,496,146 members (452 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: PHP
Good Day all

i am facing a challenge with my code. what i am trying to do is have two comboboxes one called province and the other one city, when the user selects a province it should only display the cities in that province in the city combobox. how can i achive this using PHP ?
function getCity($provinceId)
        $sql ="SELECT `cityid`,`cityname` FROM `tblcity` inner join `tblprovince` ON `tblcity`.`pid`='$provinceId'  order by `cityid` asc";
        $query = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
			$row = mysql_fetch_assoc($query);		
			$id = $row['cityid'];
			$name = $row['cityname'];
				<option value ='$id'>".$name."</option>
			$row = mysql_fetch_assoc($query);

this is what my fuction looks like now i am unable to retrieve the values of the province combo box. any help will be appreciated.

Thanks in advance
Posted 11-Mar-13 10:55am
Edited 11-Mar-13 11:01am
Matej Hlatky at 11-Mar-13 17:03pm
The option should be inside select element, which should be inside form element. Is it so?
You can access form values from $_GET or $_POST php predefined variables.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100