PHP checkboxes explained

Поділитися
Вставка
  • Опубліковано 9 лют 2025

КОМЕНТАРІ • 6

  • @BroCodez
    @BroCodez  Рік тому +2

    Document


    Pizza

    Hamburger

    Hotdog

    Taco

  • @salecar9656
    @salecar9656 Рік тому +3

    Why do we add [] after foods when setting the name in HTML when we want them to be in the same group?

    • @kristijanlazarev
      @kristijanlazarev Рік тому

      I would guess it's because when you use checkboxes, it is when you want to enable selecting multiple, and it's gonna be an array. PHP might want you to specify that it is an array. Unlike radio, where we don't use [], because it's only 1 value

    • @HHHSS956
      @HHHSS956 5 місяців тому

      If not add [ ] after "name", it only get last selected item only. That is the reason. $_POST is associative array, which has key, value pairs. Key: "foods" (the name attribute of the checkboxes)
      Value: An array of selected checkbox values (e.g., ["Pizza", "Hamburger"]).

  • @Kurt-kq9fd
    @Kurt-kq9fd 4 місяці тому

    I'll just put this in here:
    5:36
    In case some errors occur when you echo foods with numerical index, first make sure to check a box (or all boxes), then submit, the value/s should appear in the DOM.
    This happened to me just minutes ago, without checking the boxes first, a line of error occured but disappeared when I did the step above.
    I don't know the reason but the difference between the video and mine is Bro is using Windows and Chrome, I'm using Linux Mint and Firefox, mainly a speculation though.

  • @addonegn
    @addonegn Рік тому

    can you teach us advanced level of web programming