html - PHP Function multiple parameters

956

I', trying to update a row on parse using PHP. I'm using this function:

    if (isset($_GET['updateHistory']))
    {
        updateHistory($_GET['updateHistory']);
    }

    if (isset($_GET['yesNo']))
    {
        yesNo($_GET['yesNo']);
    }

function updateHistory($obId,$yesNo) {

        $bool = "";
        if ($yesNo == "YES") {
            $bool = true;
        } else {
            $bool = false;
        }

        $query = new ParseQuery("TestObject");
        try {
            $history = $query->get($obId);
            $history->set("isHistory", $bool);

            $history->save();
        } catch (ParseException $ex) {
             echo "Error Updating History";
        }
    reload();
}

The problem now is I can't pass the 2nd variable which is$yesNo using

<a href='?updateHistory=$obId&yesNo=YES'>YES</a>

How can I pass the 2nd variable? thanks!

360

Answer

Solution:

try

if (isset($_GET['updateHistory'], $_GET['yesNo'])) {
    // you should sanitize your $_GET values before using them
    updateHistory($_GET['updateHistory'], $_GET['yesNo']);
}
58

Answer

Solution:

Since your function depends on both variables being set, combine the if-statement to check both fields and do a single call to your function:

if (isset($_GET['updateHistory']) && isset($_GET['yesNo'])) {
    updateHistory($_GET['updateHistory'], $_GET['yesNo']);
}

You can then drop this part altogether:

if (isset($_GET['yesNo']))
{
    yesNo($_GET['yesNo']);
}

People are also looking for solutions to the problem: javascript - back-end error_msg is not giving a alert..!

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.