Page 1 of 1

include doesn't work..

Posted: Mon Dec 01, 2003 1:26 pm
by Klaws_wolverine
Hello all,

I have a select drop down, and a value is passed.
based on that value, I do a php include $value.html.

It doesn't work, any idea why?



PHP:
--------------------------------------------------------------------------------
<form name="dwnld" action="./inst.php" method="POST">
<select name="brandSelect" onChange="submit()">
<option selected>Select a brand ----------</option>
<option value="1">1™</option>
<option value="2">2option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>


<?php include('./folder/$brandSelect.html') ?>
--------------------------------------------------------------------------------




The include doesn't work, yes I am doing a $_POST, but still, it doesn't get included.

The include is on the same page as the form, it's a postback.
File paths are all fine
yes, 1.html, 2.html are the pages to include
I tried this: <?php if(isset($brandSelect)) include 'folder/' . $brandSelect . '.html' ; ?> Still doesn't work!


Any idea why?





Thanks

Posted: Mon Dec 01, 2003 1:38 pm
by mrvanjohnson
I think if you are going to use a variable in line you need to use double quotes.

Code: Select all

<?php
include("./folder/$brandSelect.html") 
?>
Otherwise you are literally requesting for the page $brandSelect.html.

You might want to

Code: Select all

<?php
echo $brandSelect
?>
just to make sure it's getting set to what it should be getting set to.

Posted: Mon Dec 01, 2003 5:21 pm
by uberpolak
You need to make a change to your include statement.

Either do what mrvanjohnson said (change your original to double-quoted), or use something similar to what you have in your second example.

Code: Select all

<?php
//Change
include('./folder/$brandSelect.html');

//To
include('folder/' . $brandSelect . '.html');
?>
The reason that didn't work in your if statement is that you didn't tell the if statement what to do. It should have been this:

Code: Select all

<?php
if (isset($brandSelect)) { //Dont forget the {
    include 'folder/' . $brandSelect . '.html';
} //Dont forget the }
?>