checkBox question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • info@octavum.com

    checkBox question

    novice....

    i started a php site in dreamweaver and i try fill data into MySql
    database.

    i set up a page with a form and i can fill in all the fields.

    just for one field, i like to have several checkboxes. every checkbox
    has a value, and they should fill the same field with their vale when
    checked. i also want to keep my text box, so i can write additional
    information.

    at the moment, when i click more than one checkbox, only the value of
    the first checkbox appears in the database. also, if there is already
    some data in this cell, it delete previous data, but i would like to
    keep it. preferably it should just add to information allready in the
    database.

    cheers, dimitri

  • Chung Leong

    #2
    Re: checkBox question


    info@octavum.co m wrote:[color=blue]
    > novice....
    >
    > i started a php site in dreamweaver and i try fill data into MySql
    > database.
    >
    > i set up a page with a form and i can fill in all the fields.
    >
    > just for one field, i like to have several checkboxes. every checkbox
    > has a value, and they should fill the same field with their vale when
    > checked. i also want to keep my text box, so i can write additional
    > information.
    >
    > at the moment, when i click more than one checkbox, only the value of
    > the first checkbox appears in the database. also, if there is already
    > some data in this cell, it delete previous data, but i would like to
    > keep it. preferably it should just add to information allready in the
    > database.
    >
    > cheers, dimitri[/color]

    Put [] (open and block square brackets) behind the field name so that
    the values are placed into an array, then join them together using
    implode().

    Example:

    <input type="checkbox" name="pets[]" value="dingo"> Dingo
    <input type="checkbox" name="pets[]" value="donkey"> Donkey
    <input type="checkbox" name="pets[]" value="bob dillon"> Bob Dillon
    <input type="text" name="pets[]" value="" size="8">

    .... and then ...

    $pets = implode(', ', $_POST['pets']);

    Comment

    • Timothy Larson

      #3
      Re: checkBox question

      info@octavum.co m wrote:[color=blue]
      > novice....[/color]

      Me too...
      [color=blue]
      > i started a php site in dreamweaver and i try fill data into MySql
      > database.
      >
      > i set up a page with a form and i can fill in all the fields.
      >
      > just for one field, i like to have several checkboxes. every checkbox
      > has a value, and they should fill the same field with their vale when
      > checked. i also want to keep my text box, so i can write additional
      > information.
      >
      > at the moment, when i click more than one checkbox, only the value of
      > the first checkbox appears in the database. also, if there is already
      > some data in this cell, it delete previous data, but i would like to
      > keep it. preferably it should just add to information allready in the
      > database.[/color]

      PHP can understand a field like this as an array. But it seems that you
      have to explicitly warn PHP that it might be receiving an array value by
      naming the field "xyz[]" instead of simply "xyz" in your HTML.

      Tim

      Comment

      Working...