0

I want to submit checkbox value into database.

To insert data into database, how will I use $_POST['name_value'] for the 1st case as when use for 2nd case I may use to insert data into database $_POST['m']?

1st case: <td><input type="checkbox" id="check" name="<?php echo $days;?>[]" value="<?php echo $id;?>"></td>
2nd case: <td><input type="checkbox" id="check" name="m[]" value="<?php echo $id;?>"></td>
achal naskar
  • 710
  • 1
  • 6
  • 19
  • Don't echo the name. Instead, set a hard value for each field name. And use `print` instead of `echo`. – milenmk Aug 22 '21 at 14:50
  • @milenmk Why `print` instead of `echo`? `echo` is more idiomatic in PHP. – Barmar Aug 22 '21 at 14:52
  • 1
    @milenmk That's shell, not PHP. – Barmar Aug 22 '21 at 15:03
  • @milenmk If I echo name, then what will be the problems? – achal naskar Aug 22 '21 at 15:07
  • @Barmar My bad. Here https://stackoverflow.com/questions/6878506/should-i-use-echo-or-print-in-php-scripts There are also a lot of other related articles and most people use print instead of echo. – milenmk Aug 22 '21 at 15:10
  • @milenmk Huh? Most of the answers there say that echo is better. – Barmar Aug 22 '21 at 15:11
  • 1
    Where do you get the idea that most PHP programmers use `print`? I think `echo` is overwhelmingly more common. – Barmar Aug 22 '21 at 15:12
  • @milenmk Make sure you don't count `printf()` and `sprintf()`, they're used for different purposes. – Barmar Aug 22 '21 at 15:13
  • @Bramar I know. As said, I always use `print`. Moreover, lately, I do a lot of customization of existing PHP codes and barely see `echo` being used. – milenmk Aug 22 '21 at 15:19
  • @Barmar I've been using php since v4 (not professionally) and I almost never seen anyone use `print` instead of `echo`. @achalnaskar I'm not certain what's the problem here is, but why not use `=$days?>` and `=$id?>` respectively? – vanowm Aug 22 '21 at 15:36

0 Answers0