Results 1 to 2 of 2

Thread: How to insert checkbox values to mysql

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow How to insert checkbox values to mysql

    Hi all i got a form with a few checkbox on it. User select a few of checkboxes and and press a button to write their values to db. But i do not know how to write it to mysql db. I be happy if an expert help me with that.Thanks

    Note:Assuming the table has one columns which is for id value
    code for check box form

    Code:
    <form action="./write.php" method=post >
    
    <input type="checkbox" name="id" value="1"
    <input type="checkbox" name="id" value="2"
    <input type="checkbox" name="id" value="3"
    
    <input type="submit" value="Add this/these Songs to my PlayList" name="B1">

  2. #2
    Fanatic Member neicedover1982's Avatar
    Join Date
    Jun 2005
    Posts
    566

    Re: How to insert checkbox values to mysql

    Quote Originally Posted by tony007
    Code:
    <form action="./write.php" method=post >
    
    <input type="checkbox" name="id" value="1"
    <input type="checkbox" name="id" value="2"
    <input type="checkbox" name="id" value="3"
    
    <input type="submit" value="Add this/these Songs to my PlayList" name="B1">
    If you are only allowing the user to select 1 checkbox, you just need to pass the value of $id. If you are letting them select as many as you want, since you are using an array, just write all the values like so, $id[1], $id[2] etc.

    Have a variable like "$checkbox" and then just say "$checkbox = $id[1] "," $id[2] "," $id[3] and so forth. When writing to the database, just use $checkbox and it will write the string "val1,val2,val3". When you want to call the individual numbers out of the database later, use the explode function to get each number.
    Kevin | New England Iced Over | http://www.kevincawleyjr.com

Posting Permissions

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



Click Here to Expand Forum to Full Width