if($region==region){

$result = mysql_query("SELECT * FROM places");
$row = mysql_fetch_assoc($result);
 
echo "zone: ".$row['zone'].";
}

Dani AI

Generated

The goal is to load the zone select based on the chosen region. The original post by included a comparison that used an unquoted identifier and a query that did not filter by region, so nothing useful was returned. was right to suggest checking that the region value actually arrived on the server, and was right to point out the query must select rows for that region. Combine those ideas and use a parameterized query so the result is correct and safe.

A practical server-side pattern is: confirm the request contains the region value, run a prepared query that selects only the zone column(s) for that region, return the results as JSON, and let the client populate the zone select. Example endpoint (PDO) that returns a JSON array of zones:

// zones.php (example)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['region'])) {
    $pdo = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8mb4', 'user', 'pass', [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]);
    $stmt = $pdo->prepare('SELECT zone FROM places WHERE region = :region ORDER BY zone');
    $stmt->execute([':region' => $_POST['region']]);
    $zones = $stmt->fetchAll(PDO::FETCH_COLUMN);
    header('Content-Type: application/json');
    echo json_encode($zones);
}

On the client side, send the selected region to that endpoint and replace the zone options with the returned list. Important cautions: do not use the old mysql_* extension (it is removed in modern PHP); validate and normalize the incoming region value; handle empty results gracefully; and escape output when inserting into HTML. asked for code — the snippet above plus a small fetch/DOM update will handle the common case.

Recommended Answers

All 5 Replies

What are you trying to do?

if($region==region){

should probably be

if($region=="region"){

or

if($region==$region){

who knows..

i mean to say that there's a selection box which have region values. so, whenever the region value is selected, the zone selection values from that region value has to come in the zone selection from the database. i tried that code and it didn't select from the database. i was writing that if the region is selected it must retrive its zone values of the database. this is what i mean...

post require code...

So you want the query to run if a selection is made?

if(isset($region)){
$result = mysql_query("SELECT * FROM places");
$row = mysql_fetch_assoc($result);
 
echo "zone: ".$row['zone']."";
}

If I understand you right.

You want to show the zone from a certain region.

$query = "Select * from places where region = '$region' LIMIT 1";
$result = mysql_query($query);
$row = $mysql_fetch_row($result);

echo $row;

should work. No if.

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.