Forum Moderators: open
I know this is probably going to be obvious when I get told what I'm doing wrong but here it goes anyway.
Why isn't it the drop down arenas list filling with corresponding names of the arenas when a country is chosen? As of right now nothing fills in it.
arenas.php
print '<tr>';
print '<td class="rowheading">Country</td>';
print '<td class="row3" colspan="2"><select name="countryid" class="dropdown" onchange="ajaxpage("backstageajax.php?random=625094862&routine=arenas&countryid="+showbooker.countryid.value,"arenaajax");"><option value=0>- Select -</option>';
$query = 'SELECT * FROM efed_list_arenas_countries ORDER BY `country`';
$result = mysql_query ( $query );
while ( $row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$row['country']."\">".$row['country']."</option>\r";
}
print '</select></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Arena</td>';
print '<td class="row3" colspan="2"><div id="arenaajax"><select name="arenaid" class="dropdown"><option value="0">- Select Arena -</select><input type="hidden" name="location" value="0"></div></td>';
print '</tr>';
ajax.php
<?php
if (isset($_GET['countryid'])) {$countryid=$_GET{'countryid'};}case "arenas":
print "<select name=arenaid class=dropdown><option value=0>- Select -";
$query = "SELECT
ela.id as getarenaid,
ela.city as getarenacity,
ela.arena as getarenaname,
ela.capacity as getcapacity
FROM
efed_list_arenas as ela
WHERE
ela.country_id = '$countryid'
ORDER BY
ela.arena";
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc($result))
{
$fieldarray=array('getarenaid','getarenacity','getarenaname','getcapacity');
foreach ($fieldarray as $fieldlabel)
{
if (isset($row[$fieldlabel]))
{
$$fieldlabel=$row[$fieldlabel];
$$fieldlabel=htmlentities($$fieldlabel);
}
}
print "<option value=\"".$getarenaid."\">".$getarenaname." - ".$getarenacity;
}
print "</select>\n";
break;
?>
For example:
onchange="ajaxpage("backstageajax.php?...
The browser is going to see that as:
onchange="ajaxpage("
I would start there, fix your quotes, and that might solve your problem.
onchange="ajaxpage('backstageajax.php?random=625094862&routine=arenas&countryid='+showbooker.countryid.value,'arenaajax');">
or
onchange='ajaxpage("backstageajax.php?random=625094862&routine=arenas&countryid="+showbooker.countryid.value,"arenaajax");'>
A second problem here is good error checking. Verify the value is what you expect. You are probably passing a blank value to $countryid, and since it's quoted it won't give a mysql error, it will just look for entries "where country_id='' which there probably are none.
I am guessing by the first query it's not really a numeric ID, it's a country code, so going on that assumption,
if (
isset($_GET['countryid']) and
preg_match('/^\w{2}$/i',$_GET['countryid'])
) {$countryid=$_GET['countryid']; }
else {
echo "OOPS country id is not valid input: " . $_GET['countryid'];
exit;
}
PHP bugs me in that $_GET{'countryid'} and $_GET['countryid'] are synonymous for associative arrays, in other languages [] refers only to an index, {} is an association . . . no matter here, I think . . .
The previous will "trap" the problem for you, leading to the cause and a solution, but it also validates the input - assuming, of course, it's only a two letter country code. If it's numeric,
if (
isset($_GET['countryid']) and
preg_match('/^\d+$/i',$_GET['countryid'])
) {$countryid=$_GET['countryid']; }
else {
echo "OOPS country id is not valid input: " . $_GET['countryid'];
exit;
}