Main content
<?php

    echo $test;
    include "index.php?test=solved";
    echo $test; // expected: "solved"

    if (isset($_get["test"])){
        $test = $_get["test"];
    }
?>

File ends here
error starts here.

    Notice: Undefined variable: test in C:\-------\XAMPP\htdocs\index.php on line 4
    Warning: include(index.php?test=solved): failed to open stream: No error in C:\-------\XAMPP\htdocs\index.php on line 5
    Warning: include(): Failed opening 'index.php?test=solved' for inclusion (include_path='.;C:\-------\XAMPP\php\PEAR') in C:\-------\XAMPP\htdocs\index.php on line 5
    Notice: Undefined variable: test in C:\-------\XAMPP\htdocs\index.php on line 6

What I actually try to achieve is retrieve data from same file, by using specific parameters.

Recommended Answers

You're getting an error because:
1) $test was not defined.
2) You don't use a query string when using include().

Are you just trying to get the query parameter values from the query string?

If this is index.php you would put into your address bar index.php?test=solved

Then you could do …

Jump to Post

All 2 Replies

You're getting an error because:
1) $test was not defined.
2) You don't use a query string when using include().

Are you just trying to get the query parameter values from the query string?

If this is index.php you would put into your address bar index.php?test=solved

Then you could do something like this on the page

<?php

$test = isset($_GET['test']) ? $_GET['test'] : null;

echo $test;

?>

You don't need to use file includes.

commented: Ding ding ding ding!!! +1

Answer aboved has been answered. But I don't want to create new discussion and yet ask question here. What if I want to get it's content from another file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.