Ann
Ann

Reputation: 19

If condition for dynamic variable in PHP

I have a input checkbox field, where its name generate dynamically using JavaScript.

<input type="checkbox" name="options_'.$j.'"  class="check">

Now, I want to check whether any checkbox is checked or not in if condition. I have written the following code. But it is not working. Please help me to correct the code.

for($i = 0; $i<=1; $i++)
    {
        if(!isset($_POST['options_ '.$i]))
        {
            echo $error;
        }
        $i++;
    }

Is this is the correct format?

Upvotes: 1

Views: 185

Answers (1)

caryarit ferrer
caryarit ferrer

Reputation: 326

the $i++; is not neccesary the one in the for will do it for you

Upvotes: 1

Related Questions