Hello there,
I am new to this forum and have done my best to look around for a solution to this problem.
I am using PHP to generate an HTML Select drop down menu, with 4 options:
function access_full($fi le, $access_level) {
$template = 'templates/select_tags.tmp ';
$select = file_get_conten ts($template);
$template = 'templates/drop_down_optio n.tmp';
$option = file_get_conten ts($template);
for($i = 0; $i < 4; $i++) {
$option = str_replace('#v alue#', $i, $option);
$description = access($i);
$option = str_replace('#d escription#', $description, $option);
if($i == $access_level) {
$option = str_replace('#s elected#', 'selected', $option);
} else {
$option = str_replace('#s elected#', '', $option);
}
$select = str_replace('#n ext_option#', $option, $select);
$option = file_get_conten ts($template);
}
$select = str_replace('#n ext_option#', '', $select);
$file = str_replace('#a ccess_level#', $select, $file);
return $file;
}
I am using HTML templates together with the string replace function for good practise so as to keep the coupling between my code down to a minimum.
The value selected from this drop down menu is subsequently used in an SQL statement and a database record updated:
$new_access_lev el = clean($_POST['access_level']);
$sql = "UPDATE users SET ACCESS_LEVEL='$ new_access_leve l' WHERE USER_ID='$user_ id'";
qry($sql);
The specific problem I am having is that when a user selects the option with value="0". The value stored in $new_access_lev el is '' - nothing!
I have tried using quotes either side of the 0, both '0' and "0", but none of these solutions seem to work!
I hope I am not the first person to experience this problem. If there is not solution, I can increment all the values by 1, but this will be rather time consuming as my website is becoming rather large now.
All and any help would be much appreciated.
Thanks in advance, Rob.
[More code and info available if necessary]
I am new to this forum and have done my best to look around for a solution to this problem.
I am using PHP to generate an HTML Select drop down menu, with 4 options:
function access_full($fi le, $access_level) {
$template = 'templates/select_tags.tmp ';
$select = file_get_conten ts($template);
$template = 'templates/drop_down_optio n.tmp';
$option = file_get_conten ts($template);
for($i = 0; $i < 4; $i++) {
$option = str_replace('#v alue#', $i, $option);
$description = access($i);
$option = str_replace('#d escription#', $description, $option);
if($i == $access_level) {
$option = str_replace('#s elected#', 'selected', $option);
} else {
$option = str_replace('#s elected#', '', $option);
}
$select = str_replace('#n ext_option#', $option, $select);
$option = file_get_conten ts($template);
}
$select = str_replace('#n ext_option#', '', $select);
$file = str_replace('#a ccess_level#', $select, $file);
return $file;
}
I am using HTML templates together with the string replace function for good practise so as to keep the coupling between my code down to a minimum.
The value selected from this drop down menu is subsequently used in an SQL statement and a database record updated:
$new_access_lev el = clean($_POST['access_level']);
$sql = "UPDATE users SET ACCESS_LEVEL='$ new_access_leve l' WHERE USER_ID='$user_ id'";
qry($sql);
The specific problem I am having is that when a user selects the option with value="0". The value stored in $new_access_lev el is '' - nothing!
I have tried using quotes either side of the 0, both '0' and "0", but none of these solutions seem to work!
I hope I am not the first person to experience this problem. If there is not solution, I can increment all the values by 1, but this will be rather time consuming as my website is becoming rather large now.
All and any help would be much appreciated.
Thanks in advance, Rob.
[More code and info available if necessary]
Comment