Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with Undefined Index

    Hi, Can you please help me fix this code?
    <?php
    switch($_POST['API'])
    {
    case 1: getCompanies();
    break;
    case 2: getDepartments($_POST['company']);
    break;
    case 3: getCourses($_POST['company'],$_POST['department']);
    break;
    case 4: getXMLs($_POST['company'],$_POST['department'],$_POST['course']);
    break;
    case 5: downloadXML($_POST['company'],$_POST['department'],$_POST['course'],$_POST['xmlname']);
    break;
    default:break;
    }
    function getCompanies()
    {
    $dir = @opendir("CaptivateResults");
    if($dir != "")
    {
    while(($file = readdir($dir)) !== false)
    {
    if(!is_file($file))
    echo $file.";";
    }
    closedir($dir);
    }
    else
    echo "No Captivate Results found;";
    }
    function getDepartments($comp)
    {
    $dir = @opendir("CaptivateResults"."/".$comp);
    while (($file = readdir($dir)) !== false)
    {
    if(!is_file($file))
    echo $file.";";
    }
    closedir($dir);
    }
    function getCourses($comp,$dept)
    {
    $dir = @opendir("CaptivateResults"."/".$comp."/".$dept);
    while (($file = readdir($dir)) !== false)
    {
    if(!is_file($file))
    echo $file.";";
    }
    closedir($dir);
    }
    function getXMLs($comp,$dept,$course)
    {
    $dir = @opendir("CaptivateResults"."/".$comp."/".$dept."/".$course);
    $directory = "CaptivateResults"."/".$comp."/".$dept."/".$course;
    while (($file = readdir($dir)) !== false)
    {
    if(!(is_dir($file)) && findexts($file) == 'xml')
    {
    echo $file.",".number_format(filectime($directory."/".$file),0, '.', '').";";
    }
    }
    closedir($dir);
    }
    function downloadXML($comp,$dept,$course,$name)
    {
    $dir = "CaptivateResults"."/".$comp."/".$dept."/".$course."/".$name;
    $handle = fopen($dir, "r");
    $contents = fread($handle, filesize($dir));
    fclose($handle);
    echo $contents;
    }
    function findexts ($filename)
    {
    $filename = strtolower($filename) ;
    $exts = explode(".", $filename);
    $n = count($exts)-1;
    $exts = $exts[$n];
    return $exts;
    }
    ?>
    I am getting an undefined index error on line 2 - Switch($_POST['API'])
    Thanks
    Terra

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    That means the index "API" doesn't exist in the $_POST array.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •