Cannot access disabled select options

Hi, I am working on an hotel reservation site and I found a nice project with hbportal that I am customizing. The problem I am having is with the drop down select options.This is the code in the index page:


					<td>
						City:
					</td>
					<td>
						<div id="citydiv" name="citydiv">
						<select name="city" id="city" disabled>
							<option>No cities  Available</option>
						</select>
						</div>
					</td>

and this is the php script:

<?php
	session_start();
	include "includes/configuration.php";
	$con=mysql_connect($location,$username,$password);
	mysql_select_db($database_name);
	mysql_set_charset('utf8',$con);
	include "includes/database_add.php";
	include "includes/language.php";
	//Set language
	if(isset($_GET['lang'])){
		$_SESSION['lang']=$_POST['lang'];
		$lang=$_SESSION['lang'];
	}else if(isset($_SESSION['lang'])){
		$lang=$_SESSION['lang'];
	}else{
		$lang="English";
	}
	//end of set language
	$query="SELECT * FROM cities JOIN countries ON cities.country_id=countries.id WHERE country='".$_POST['country']."'";
	$result=mysql_query($query);
	echo "<select name=\\"city\\" id=\\"city\\">";
	if(mysql_num_rows($result)==0){
		echo "<option value=\\"No Cities Available\\">No Cities Available</option>";
	}else{
		while($row=mysql_fetch_array($result)){
			echo "<option value=\\"".$row['city']."\\">".$row['city']."</option>";
		}
	}
	echo "</select>";
?>

I have replaced No Cities Available in the first option value adding the cities I want like Florence, Venice etc.but I still get a ghosted’No cities Available".I know that something must be amended in the php code but I don’t know what, can you please help me? Thanks a lot.

Have you checked that your query has results? It might be that the query is incorrect or throwing an error. Try adding or die(mysql_error()); at the end of the mysql_query($query) line.

What I’m confused about is where the “disabled” is coming from. Your PHP has

echo "<select name=\\"city\\" id=\\"city\\">";

but the HTML output is

<select name="city" id="city" disabled>

I am surprised Mittineague didn’t say anything but before you get to far into your code you want to read this STOP using MySQL migrating to procedural mysqli as you might find yourself updating the code in the near future.

It is not to hard to update the code but you might as well do it all at the same time.

Agreed about mysql…

I believe you need to define what table the WHERE country is referring to.

$query="SELECT * FROM cities JOIN countries ON cities.country_id=countries.id WHERE cities.country='".$_POST['country']."'"; 

It’s also a bad idea POSTing directly to your database. At the very least use mysql_real_escape_string();

$country = mysql_real_escape_string($_POST['country']);
$query="SELECT * FROM cities JOIN countries ON cities.country_id=countries.id WHERE cities.country='$country'";