Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assigning variable value from list box 1

Status
Not open for further replies.

canajun

Programmer
Sep 28, 2002
57
0
0
CA
I am trying to assign a value to a variable from a selection in a list box generated by the following code:
Code:
<form action="rateadmin.php" method="post">
        <select name="file">
                   <? $folder = "rates/";
                   $handle = opendir($folder);
                   while ($file = readdir($handle))
                   {
                   $files[] = $file;
                   }
                   closedir($handle);
                   foreach ($files as $file) {
                   print "<option value=$folder$file>$file</option>";
                   }
                   ?>
                   </select><input name="" type="submit" value="Get File" />
</form>

Then I want to include the file selected from above, in the rest of the file (files contain variables used to populate text fields in a form)

Something like:

Code:
$filea = addslashes($_POST['file']);
if (isset($filea)) {
    include $filea;
}
I do not want to include anything, if no file is selected (or the variable $filea is not set)..

I am having trouble with this.. can anyone help?
 
I would fist check whether or not $_POST['file'] is actually populated.

If its populated, the you can run it through addslashes, and check that the file actually exists.

Code:
if(isset($_POST['file'])){
  $filea=addslashes($_POST['file']);
  if(file_exists($filea)){
   include($filea);
   }

}

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top