HTML:
(Some context first, the snipped I am about to share below this is within a loop. This is the loop, and it's based on data from the index file):
<?php
foreach ($field_data[$i] as &$field) {
$field_name = $field[0];
$table = $field[1];
$table_field_name = $field[2];
$field_type = $field[3];
$iteration = $field[4];
$clean = ($iteration >= 0 ? $clean[$table][$iteration][$field_name] : $clean[$table][$field_name]);
... The code snippet that is causing me issues:
<!-- Countries -->
<?php } else if ($field[5] == 'country') { ?>
<select class="select" id="<?php $field_name ?>" name="<?= $table_field_name ?>" <?php if ($required_fields[$table][$i][$field_name] != null || $required_fields[$table][$field_name] != null) { ?> required <?php } ?> >
<option value=""></option>
<?php foreach ($select['countries_all'] as $dropdown_field) { ?> <!-- This is defined in pd_request_form.php -->
<!-- Country -->
<?php if ($field_name == 'country_id') { ?>
<option value="<?php echo $dropdown_field['country_id']; ?>" <?php if ($dropdown_field['country_id'] == $clean) { ?>selected<?php } ?>><?php echo $dropdown_field['country_name']; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php } else if ($field[5] == 'citizenship_country') { ?>
<select class="select" id="<?php $field_name ?>" name="<?= $table_field_name ?>" <?php if ($required_fields[$table][$i][$field_name] != null || $required_fields[$table][$field_name] != null) { ?> required <?php } ?> >
<option value=""></option>
<?php foreach ($select['citizenship_countries_all'] as $dropdown_field) { ?> <!-- This is defined in pd_request_form.php -->
<!-- Citizenship Country -->
<?php if ($field_name == 'pd_citizenship_country_id') { ?>
<option value="<?php echo $dropdown_field['country_id']; ?>" <?php if ($dropdown_field['country_id'] == $clean) { ?>selected<?php } ?>><?php echo $dropdown_field['country_name']; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php } ?>
PHP Index file:
$tab[$i][15] = array("pd_citizenship_country_id","c_pd", "c_pd[$i][pd_citizenship_country_id]","select", $i, 'citizenship_country');
$tab[$i][16] = array("pd_dietary_restrictions", "c_pd", "c_pd[$i][pd_dietary_restrictions]","textarea", $i);
Select defined here in the same index file:
// Countries
$select['countries_all'] = $c_lookup->getCountriesSelect(TRUE);
$select['countries_current'] = $c_lookup->getCountriesSelect(FALSE);
// Countries
$select['citizenship_countries_all'] = $c_lookup->getCountriesSelect(TRUE);
$select['citizenship_countries_current'] = $c_lookup->getCountriesSelect(FALSE);
Lookup file:
/**
* Get Countries Select
*
* Returns the countries array for use in the countries select drop-down.
*/
function getCountriesSelect($param_all=FALSE, $format='HTML')
{
$sql;
$result = FALSE;
if ($format == '')
{
$format = 'HTML';
}
$sql = "SELECT country_id, country_name, country_order
FROM c_country
WHERE country_status_id = 'A' ";
if (!$param_all)
{
$sql.= "AND country_current_b = 'Y' ";
}
$sql.= "ORDER BY country_order, country_name";
$result = $this->c_db->Execute($sql);
if ($result)
{
$countries = array();
$country_order = '';
while (!$result->EOF)
{
$row = array();
$row_html = array();
$row = $result->FetchRow();
if ($format == 'HTML')
{
$row_html['country_id'] = htmlentitIes($row['country_id'], ENT_QUOTES, $this->html_encoding);
$row_html['country_name'] = htmlentitIes($row['country_name'], ENT_QUOTES, $this->html_encoding);
$row_html['country_order'] = htmlentitIes($row['country_order'], ENT_QUOTES, $this->html_encoding);
}
else
{
$row_html['country_id'] = $row['country_id'];
$row_html['country_name'] = $row['country_name'];
$row_html['country_order'] = $row['country_order'];
}
$countries[] = $row_html;
}
}
else
{
error_log("ERROR: getCountriesSelect: " . $this->c_db->ErrorMsg() . ": SQL: $sql");
return false;
}
return $countries;
}
And the problem is, in the database, pd_citizenship_country_id is never saving, while country_id saves. Why?