hi everyone
i need help in my query which is that:
1.which country name i selected from my dropdown list
2.when i select any country_name its show more info in new page.php like (this selected name show more information about country_name e.g. its captical, and cities through database in new page)

and here is my code:

<tr> <td>Country Name</td> <td> <select name="name"> <?php
      $conn = oci_connect("username", "pswrd", "db");
      $sql = 'SELECT name FROM country';
      $stid = oci_parse($conn, $sql);
      $success = oci_execute($stid);
      while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) 
      {
        echo "<option value=\"countryname1\">" . $row['NAME'] . "</option>";
      }
    ?> 

Dani AI

Generated

Short answer: use the country primary key as the <select> value, submit the form to a detail page, then fetch the country row plus its cities by that ID with a bound query. is right to recommend sending an ID — matching by name is fragile (duplicates, accents, casing). : the detail page should validate the incoming ID, query the DB with a bind parameter, and render the country + a loop of cities.

Example (detail page) — minimal, secure pattern:

<?php
// country-details.php
$id = filter_input(INPUT_POST, 'country_id', FILTER_VALIDATE_INT);
if (!$id) { echo 'No valid country selected.'; exit; }

$conn = oci_connect('DBUSER','DBPASS','DB');
$sql = "
  SELECT c.name AS country_name, c.capital, ci.name AS city_name
  FROM countries c
  LEFT JOIN cities ci ON ci.country_id = c.id
  WHERE c.id = :id
  ORDER BY ci.name
";
$stid = oci_parse($conn, $sql);
oci_bind_by_name($stid, ':id', $id);
oci_execute($stid);

$country = null;
$cities = [];
while ($r = oci_fetch_array($stid, OCI_ASSOC)) {
  if ($country === null) $country = ['name'=>$r['COUNTRY_NAME'],'capital'=>$r['CAPITAL']];
  if (!empty($r['CITY_NAME'])) $cities[] = $r['CITY_NAME'];
}

if (!$country) { echo 'Country not found.'; exit; }

echo 'Country: '.htmlspecialchars($country['name'])."<br>";
echo 'Capital: '.htmlspecialchars($country['capital'])."<br>";
echo 'Cities:<br>';
foreach ($cities as $i=>$c) echo ($i+1).'. '.htmlspecialchars($c)."<br>";

oci_free_statement($stid);
oci_close($conn);
?>

Notes and troubleshooting:

  • Prefer a separate cities table (one-to-many) instead of comma lists. Example schema: countries(id PK, name, capital), cities(id PK, country_id FK, name).
  • Always escape output with htmlspecialchars() to avoid XSS.
  • Use filter_input() or cast to int to validate the submitted ID; use binds (oci_bind_by_name) to avoid injection.
  • If you see empty results, check column names (OCI returns uppercase keys), confirm your JOIN, and test the query directly in SQL*Plus/SQL Developer first.
  • If you must use GET (bookmarkable links), validate with INPUT_GET and consider country.php?id=123.

This gives a clear, maintainable flow: populate options with the country id, submit, validate, then query and render the details.

Recommended Answers

All 4 Replies

Select also ID of country.

<tr> <td>Country Name</td> <td> <select name="countryID"> <?php
      $conn = oci_connect("username", "pswrd", "db");
      $sql = 'SELECT id,name FROM country';
      $stid = oci_parse($conn, $sql);
      $success = oci_execute($stid);
      while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) 
      {
        echo "<option value=\"" . $row['ID'] . "\">" . $row['NAME'] . "</option>";
      }
    ?>

i want to dispaly all data in new page.php which i was selected country name from dropdown list

e.g.

  1. i select country_name from dropdown list (AUSTRALIA)
  2. open new page.php ans its show like that
    country name: AUSTRALIA
    Capitical:
    City1: ____
    City2:

    City3:____
    these all information pick from oracle database table country_detail

You can select by country name but it is not good practice

    echo "<option value=\"".$row['NAME']."\">".$row['NAME']."</option>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.