Reputation: 79
Tried to do this but it's only echoing the value not actually choosing the .php file to include into the same page. The code is below...
<body>
<form name="form1" method="POST" action="test.php">
<select name="select" onChange="document.form1.submit()">
<option selected>Select an Industry</option>
<option value="members">members</option>
<option value="Female">Female Members</option>
</select>
</form>
<?php
$file = $_POST['select'];
echo $file;
$path_file = $_SERVER['DOCUMENT_ROOT']/$file.php;
if(file_exists($path_file))
{
echo("The file does not exist at: $path_file");
}
else
{
require_once($path_file);
}?>
</body>
Once sorted I am hoping it will include a php file into the same page! Also need a default page before changing it, so Members be the main page, then people can select Female to see just female etc.
Upvotes: 0
Views: 1512
Reputation: 123
Change
$path_file = $_SERVER['DOCUMENT_ROOT']/$file.php;
to
$path_file = $_SERVER['DOCUMENT_ROOT']."/".$file.".php";
But this is very bad for security (you can't trust _POST data). Better change to something like:
if (isset($_POST['select']) && $_POST['select'])
{
if ($_POST['select'] == 'something')
include 'something.php';
if ($_POST['select'] == 'somethingelse')
include 'another.php';
} else {
include 'default.php';
}
Upvotes: 1