I have a form that contains a list box that is filled by an array. When the form is submitted, it returns the index number of the selected item of the array of items in the list box, not the value. The value is what I need, not the index number of the selected item.
Can someone please examine my code below and tell me why this is so.
Thanks so much in advance.
<?php
$conn = ftp_connect("ftp.mysite.com") or die("Could not connect");
ftp_login($conn,"username","password");
$content=(ftp_nlist($conn,"public_html/testing"));
ftp_close($conn);
//foreach ($content as $value) {
//echo $value;
//}
?>
<font color='red'>Array filled selectbox: </font>
<br>
<form method="POST" action="<?php echo $PHP_SELF;?>">
<?php
selectboxArrayFill($content, "Arraybox"); //fill select box
function selectboxArrayFill(&$array, $selboxname){
echo '<SELECT size="8" name="'. $selboxname.'" >';
//Note: the while(list)=each()) is equivalent to:
//foreach($array as $key => $value){
reset($array);
while(list($key, $value)= each($array)){
//Check for omitted values, and correct
//if(trim($key)=="")$key=$value;
//if(trim($value)=="")$value=$key;
if(trim($value)!=="." && trim($value)!=="..")
{
//Emit option
echo "\n <OPTION value='".$key."'>".$value."</OPTION>";
}
}
//Close select control (not use of newlines for HTML formatting
echo "\n</SELECT>\n";
}
?>
<input type="submit" name="delete" value="Select files and delete">
</form>
<br><br>
<?php
if (isset($_POST['delete']))
{
$fileToDelete= $_POST['Arraybox'];
echo $fileToDelete; //returns array index number not value here
Other code here....
?>