0
<input type='checkbox' id='checkbox-" . $counter ."' class='mdl-checkbox__input' name='product[]' value='$counter'>

for some reason, when I run the form with this name for this input, it won't run the PHP script, it won't even run the beginning of the script.

Is there some reason this isn't working? am I doing it wrong? I thought this is the actual way this would work.

[Edit] this is the actual full script in the form:

foreach($producten as $row)
{
    echo("
    <label class='mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect' for='checkbox-" . $counter ."'>
    <input type='checkbox' id='checkbox-" . $counter ."' class='mdl-checkbox__input' name='product[]' value='$counter'>
    <span class='mdl-checkbox__label'>" . $row['productcode'] . ' ' . $row['categorie'] . ' ' . $row['merk'] . ' ' . $row['type'] . ' ' . $row['cpu'] . ' ' . $row['ram'] . ' ' . $row['os'] . ' ' . $row['hdd'] . ' ' ."</span>
    </label>
    ");
    $counter++;
}
7
  • Can you post the PHP script please? Commented Jun 20, 2016 at 9:23
  • use $counter inside php tag Commented Jun 20, 2016 at 9:23
  • echo("meep"); if(isset($_POST['leerlingnr']) && isset($_POST["inleverdatum"]) && isset($_POST['product'])) { is the beginning of the script, though as I stated, it won't even echo "meep". Commented Jun 20, 2016 at 9:24
  • @Saty what do you mean? can you give an example? Commented Jun 20, 2016 at 9:24
  • 1
    It's incomplete code, is it like : <?php echo "<input type='checkbox' id='checkbox-" . $counter ."' class='mdl-checkbox__input' name='product[]' value='$counter'>"; ?> Commented Jun 20, 2016 at 9:25

1 Answer 1

2

enter image description here.
I have checked with below code as related your code. It's working with Checkbox array. I hope it's will help you. All the best.

 <form action="#" method="POST">
    <?php
    $producten = array('1a','2b','3c','4d');
    $counter = 1;
    foreach($producten as $row)
    {
        echo("
        <input type='checkbox' id='checkbox-" . $counter ."' class='mdl-checkbox__input' name='product[]' value='$row'> <label class='mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect' for='checkbox-" . $counter ."'> $row </label><br>
        ");
        $counter++;
    }
    ?>
    <input type="submit" name="submit" value="Submit">
</form>
<?php echo "<pre>"; print_r($_REQUEST); ?>

Output:

Array

( [product] => Array ( [0] => 1a 1 => 2b [2] => 3c [3] => 4d ) )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.