This discussion is archived
1 Reply Latest reply: Nov 11, 2012 4:58 PM by cj RSS

country state drop down list oracle & php

973661 Newbie
Currently Being Moderated
Hi all.

I'm new in this forum.

I have created two tables :

create table countries
country_id int not null,
country_name varchar2(50),
constraint countries_country_id_pk primary key (country_id)

create table states
state_id int not null,
state_name varchar2(50),
country_id int,
constraint states_state_id_pk primary key (state_id),
constraint states_country_id_fk foreign key (country_id) references countries (country_id)on delete cascade

and insert data.

I have connect to oracle database by this php file.

$conn = oci_connect('hr', 'hekal', 'or');
if (!$conn)
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

then I make combobox dropdown list like that

include ('../connect_db.php');
$sql = 'select * from countries order by country_name';
$stid = oci_parse($conn, $sql);
oci_define_by_name($stid, 'country_id', $country_id);
oci_define_by_name($stid, 'country_name',$country_name);
<select name="country">
while (oci_fetch($stid)) {
<option value="$country_id" id="country_id"> <?php echo"$country_name" ; ?></option>
<?php } ?>

This code get values into drop down list

and make another to the states.

But I need to connect the two each other.

I need when I choose USA. the other list show only states of USA

thank you


  • Correct Answers - 10 points
  • Helpful Answers - 5 points