Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use a PHP function to include a file based on a GET parameter and load a default file if the GET parameter is not set?

I want to ensure that the correct file is loaded depending on whether the GET parameter site is present or not. Can someone tell me what I am doing wrong or how to get this right?
I need also an MakeStatement function. The parameters are: $query and $array is there anything to improve about this code? Thanks!

Can anyone help me to complete my code or write it correctly?

function getSite($site) {
    if(isset($_GET['site'])) {
        include_once($_GET['site']);
    } else {
        include_once($site);
    }
}

function makeStatment($query, $array = null)
{
    $stmt = $con->prepare($query);
    $stmt->execute($array);
    return $stmt;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try using this

function getSite($site)
{
    if(isset($_GET['site']))
    {
        include_once('site/'.$_GET['site'].'.php');
    } 
    else
    {
        include_once('site/'.$site.'.php');
    }
}

function makeStatment($query, $array = null)
{
    try 
    {
        global $con;
        $stmt = $con->prepare($query);
        $stmt->execute($array);
        return $stmt;
    } 
    catch (Exception $e)
    {
        return $e;
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading