Unable to pass variable to sec. set of code

Hello all,
I cant seem to pass one of the variables through for somereason.
This is a script containg 3 dropdown box. the country and the state dropdown box works but the city wont… cant seem to pass the country through to the next code.


<?php
require_once("C:\\wamp\\www\\servicebid\\inc\\connection.php");
[B]$country = $_GET['country']; // works.. tested[/B]

$provinceState_query = "SELECT DISTINCT province from tb_location where country = '$country'";
$result= mysqli_query($dbconnect, $provinceState_query) or die('<br/>Error reading Database:'.mysql_error());

?>
// problem area.. getcity isnt taking the country code
<[B]select name="state" onchange="getCity('<?=$country?>',this.value)">[/B]
<option>Select State</option>
<?php
	while($row=mysqli_fetch_assoc($result)) 
		{ echo '<option value="' . $row['province'] . '">' . $row['province'] . '</option>'; }
echo '</select>';	
?>

This is the city dropdown box but the state variable is comming through but not the country… the country should come from the above code.

Any idea what im doing wrong?

<?php
require_once("C:\\wamp\\www\\servicebid\\inc\\connection.php");
$countryId = $_GET['country']; //not receiving the variable from the above code
$stateId = $_GET['state']; //works

echo '<br> ==>:1'.$countryId; // not pulling
echo '<br> ==>:2'.$stateId;	 // pulling

$city_query = "SELECT city from tb_location WHERE country ='$countryId' AND province='$stateId'";
$result= mysqli_query($dbconnect, $city_query) or die('<br/>Error reading Database:'.mysql_error());

while($row1=mysqli_fetch_assoc($result)) 
{  //testing
	echo 'br>'.$row1['city'];
}
?>
<select name="city">
<option>Select City</option>
<?php 
while($row=mysqli_fetch_assoc($result)) 
{	echo '<option value="' . $row['city'] . '">' . $row['city'] . '</option>'; }
?>
</select>

If you view-source what does the select’s onchange look like? Maybe you need to use “echo” instead of “=” ??

Yeah, the “<?=” tags are deprecated (I think) and not always supported.

It’s a little more verbose, but like Mittineague says it’s best to always use “<?php echo” instead.

Someone else mentioned that yesterday, but from googling I can find nothing to support. Seems they will be around for ever. Personally I use “<?php echo” as “<?=” is server dependent (and PERDIR)

no, it is not deprecated.
it is just disabled by default

http://php.net/manual/en/ini.core.php
default = 1

meh, just don’t use them and feel free to not care what the f they are set to :stuck_out_tongue:

there could be another problem if you have the same name for two select elements

I wasn’t sure if they were deprecated or not, guess not (pity).

I don’t like them at all, short tags should be banned :slight_smile:

I don’t understand such emotions.
If you don’t like it - just don’t use it. Why bother yourself with things you have no relation to?

Hello All,
The problem still unresolved. I took some of your suggestions and when back to the code and i’am missing something…lol

I put in a lot of echo statement and alerts to identify the problem and narrowed it down but im still not sure how to solve the problem.

The problem is within this code and the js which ill post below:
The variable country exists but not going through the script.


<?php
require_once("C:\\wamp\\www\\servicebid\\inc\\connection.php");
echo $country = $_GET['country']; // works.. tested

$provinceState_query = "SELECT DISTINCT province from tb_location where country = '$country'";
$result= mysqli_query($dbconnect, $provinceState_query) or die('<br/>Error reading Database:'.mysql_error());

?>
// problem area.. getcity isnt taking the country code
<select name="state" [COLOR="Red"][B]onchange="getCity('<?=$country?>',this.value)"[/B][/COLOR]>
<option>Select State</option>
<?php
	while($row=mysqli_fetch_assoc($result)) 
		{ echo '<option value="' . $row['province'] . '">' . $row['province'] . '</option>'; }
echo '</select>';	
?>

the JS


[COLOR="Red"][B]function getCity(country,stateId) 
{	alert('Country==>:' + country + ' State==>: ' + stateId + '.');[/B][/COLOR]	
var strURL="findCity.php?country="+country+"&state="+stateId;	var req = getXMLHTTP();	if (req) 	{	req.onreadystatechange = function() 		{	if (req.readyState == 4) 			{	if (req.status == 200) 				{	document.getElementById('citydiv').innerHTML=req.responseText;	} 				else				{	alert("There was a problem while using XMLHTTP:\
" + req.statusText);	}			}						}					req.open("GET", strURL, true);		req.send(null);	}}

If I remember correctly <?= is going to be depreciated in php6 but <? will still remain. If you don’t want to have to worry about short tags compatibility then stick with <?php

According to my wifes cousins brothers friends dog, <?php is going to be deprecated in favour of <?php_hypertext_processor to clear up the naming confusion. You’d be surprised how many wrongly think it stands for post hyperspatial proxy.

Everyone is already confused enough about short tags, if you don’t know than don’t say. Particularly you orange guys :stuck_out_tongue:

I hacked it up quite a bit for testing, but

<html><head><title>State test</title>
<script type='text/javascript'>
function getCity(country,stateId) 
{
	alert('Country==>: ' + country + ' State==> : ' + stateId);
}
</script>
</head>
<body>
<?php
$all_states = array('Pennsylvania', 'Virginia', 'Vermont', 'Utah', 'Florida', 'California');
$country = 'US';
?>
<!-- problem area.. getcity isnt taking the country code -->
<select name="state" onchange="getCity('<?=$country?>',this.value)">
<option>Select State</option>
<?php
foreach($all_states as $state) 
{
	echo '<option value="' . $state . '">' . $state . '</option>' . "\
";
}
echo '</select>';    
?>
</body></html>

creates this mark-up

<html><head><title>State test</title>
<script type='text/javascript'>
function getCity(country,stateId) 
{
	alert('Country==>: ' + country + ' State==> : ' + stateId);
}
</script>
</head>
<body>
<!-- problem area.. getcity isnt taking the country code -->
<select name="state" onchange="getCity('US',this.value)">
<option>Select State</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Virginia">Virginia</option>
<option value="Vermont">Vermont</option>
<option value="Utah">Utah</option>

<option value="Florida">Florida</option>
<option value="California">California</option>
</select></body></html>

and the alert() works fine.

Maybe throw in a var_dump($result) or var_dump($row) into the mix to make sure your query is working?

Anyway, what does the view-source look like?

Yeah…
<digs toe into the ground>

Sorry :blush:

The short tags will forever and always, (until further notice) be supported in PHP.