LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   php include (https://www.linuxquestions.org/questions/programming-9/php-include-197282/)

msound 06-24-2004 02:43 PM

php include
 
alrighty let me explain what I'm trying to do. I made an online form where a user can choose a month and a week then hit submit. The php page it POST's to turns the to variables into a string

$mon = $_POST[month];
$week = $_POST[week];

$getfile = $mon$week.php;

include ($getfile);

Pretty darn easy right? Well the problem is I don't know how to write a check function that makes sure the file exists before php tries to include it. Basically when the user enters a month and week that I don't have a file for I get a long php error message. I'd like to set it up so it just displays a message "Sorry we do not have a file for that month and week". Any help would be greatly appreciated.

logicdisaster 06-24-2004 03:15 PM

use file_exists($getfile);
so
$mon = $_POST[month];
$week = $_POST[week];

$getfile = $mon$week.php;
if(file_exists($getfile)){
include ($getfile);
} else {
echo "Error Message";
}

msound 06-24-2004 04:21 PM

awesome, thanks for the reply I'll try it first thing tomorrow morning!


All times are GMT -5. The time now is 09:23 PM.