SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member gemini_bwoy's Avatar
    Join Date
    Oct 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Slight Checkbox problem?

    Good days, guys

    My database is up and running, and my normal text fields works properly, I am not sure about how to approach checkboxes, I want to know how I can make it so when one is choosen, that data goes to my databases as checked.
    I have reasonable knowledge about php etc.
    I though of create a new field in myphpAdmin , for my two checkboxes, but I want sure what type of fields it should be. eg.) INT, char,

    I was thinking of like, a selection field, but I dont see that option.

    Also, what code would i have to write in the html for this:

    This is what I have so far:

    PHP Code:
    {
       
    $joketext $_POST['joketext'];
    $loctext $_POST['loctext'];
    $audioTime $_POST['audioTime'];
    $linktext $_POST['linktext'];
    $rushBox $_POST['rushBox'];
       
    $sql "INSERT INTO joke SET
          loctext='
    $loctext',
           joketext='
    $joketext',
           rushBox='
    $rushBox',
           audioTime='
    $audioTime',
            linktext='
    $linktext',
           jokedate=CURDATE()"
    ;

       if (@
    mysql_query($sql)) {
         echo 
    '<p>Your joke has been added.</p>';
       } else {
         echo 
    '<p>Error adding submitted joke: ' .
             
    mysql_error() . '</p>';
       }

    rushbox is the checkbox, that im trying to implenment, I know what it cant be the same way as the normal text, but I was just trying something.


    Thanks

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As it's a checkbox it can only have 2 values, like yes or no for example, so you can use an ENUM column type, ENUM('no', 'yes') where 'no' would be the default (if they didn't check the checkbox).
    $_POST['rushBox'] will only be set if they check the box so you could do:
    $rushBox = isset($_POST['rushBox']) ? 'yes' : 'no';

  3. #3
    SitePoint Member gemini_bwoy's Avatar
    Join Date
    Oct 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks marks
    lemme try it

  4. #4
    SitePoint Member gemini_bwoy's Avatar
    Join Date
    Oct 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea, it WORKS

    thanks

  5. #5
    winter is around the corner Tomer's Avatar
    Join Date
    Jul 2005
    Location
    Israel
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Usually using 0 and 1 makes the most sense. 1 being yes, and 0 no.

    - Tomer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •