0
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.

Edited by RikTelner

2
Contributors
2
Replies
15
Views
3 Years
Discussion Span
Last Post by RikTelner
1

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.

Votes + Comments
Ding ding ding ding!!!
0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.