Monday, 22 April 2013

Fill country state city using php mysql

For selecting country in drop down list
The states are also filled auto matically from the database table as shown in the above figure.

<html>
<head>
<title>Fill Dropdown list</title>
<script language="javascript" type="text/javascript">
function showState(Country_Id)
{
 document.frm.submit();
}

</script>
</head>
<body>
<form name="frm" id="frm">

<?php
$con=mysqli_connect(@"localhost", "root", "","demo") or die("Connection Failed");
$query = "SELECT * FROM tbl_country";
$result = mysqli_query($con,$query);
?>
<select name="select1"  onChange="showState(this.value);">
<option value="">--- Select Country---</option>
<?php
while ($line = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $line['id'];?>" <?php if($line['id']==$_REQUEST["select1"]) { echo

"Selected"; } ?> > <?php echo $line['countryname'];?> </option>
<?php
}
?>
<?php
$con=mysqli_connect(@"localhost", "root", "","demo") or die("Connection Failed");
$query = "SELECT * FROM tbl_state where cid='$_REQUEST[select1]'";
$result = mysqli_query($con,$query);
?>
</select>
<select name="select2"  >
<option value="">--- Select State---</option>
<?php
while ($line = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $line['sid'];?>"> <?php echo $line['statename'];?> </option>
<?php
}
?>
</select>
</form>
</body>

</html>

For Learn Project Training with PHP Technologies
Visit Website : PHP Project Training Institute Vadodara, Gujarat, India.

24 comments:

  1. can you send the code with database file.

    ReplyDelete
  2. Plz send the code with database file.(nikhilkamble2009@gmail.com)

    ReplyDelete
  3. please send this code to me also...
    hbtarkel94@hotmail.com

    ReplyDelete
  4. me too : niralshah.251@gmail.com

    ReplyDelete
  5. me too, hemanth.greenfish@gmail.com

    ReplyDelete
  6. can you send the code with database file

    ReplyDelete
  7. hi, can I also ask for the dBase file? thank you

    ReplyDelete
    Replies
    1. please send in my email jcsalegre@gmail.com

      Delete
  8. mayanksinghchauhan18@gmail.com
    send the code with database

    ReplyDelete
  9. please send the code to this email id

    danishkhan989@gmail.com

    ReplyDelete
  10. send me
    rahul.laabhaa@gmail.com

    ReplyDelete
  11. Sir,
    Can you please send me the source code in the given email id
    shanawaj@gmail.com
    Thanks in Advance.

    ReplyDelete

  12. Computer Training Institute Vadodara. Java, Advanced Java, Android, ASP.Net, PHP, CMS, SEO, Project Training, Oracle, SQL Server, MySQL, Data Structures, Algorithms, System Programming, DBMS, OS, C, C++ Programming, HTML, CSS, Web Design, JavaScript, JQuery, AJAX, etc.
    More Details Visit : http://www.vataliyatuitionclasses.com

    ReplyDelete
  13. plz send mi code n db file


    id

    pnsonawane11@gmail.com

    ReplyDelete
  14. Can you please send code and database. I notice this is country/state drop downs. Will you include cities drop down. Select country from drop down, on select state in 2nd drop down then on select cities in 3rd drop down.

    ReplyDelete
  15. Can you please send code and database. I notice this is country/state drop downs. Will you include cities drop down. Select country from drop down, on select state in 2nd drop down then on select cities in 3rd drop down.

    ReplyDelete
  16. Can you please send code and database. I notice this is country/state drop downs. Will you include cities drop down. Select country from drop down, on select state in 2nd drop down then on select cities in 3rd drop down.

    ReplyDelete
  17. code is working fine but it clears all the textbox and dropdown to default value on the existing page where i am using this..
    Admin please help me with the issue..

    ReplyDelete
  18. Pls send me full code with all files at pkhushboo16@gmail.com

    ReplyDelete
  19. ple send me a complete source code at panneerrathinam@gmail.com

    ReplyDelete