Results 1 to 4 of 4

Thread: send value into database table using ckeckbox

  1. #1
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default send value into database table using ckeckbox

    Hi all,

    I have four check box, i want to send 1st & 4th value of the check box into database table after selecting one or more option. ie if i select the dating and Networking, the both should store into database. example: dating, Networking in table.
    I am taking the four variable and using comma i am separting the variable. But problem is that once i am select the 1st and 4th option three comma is coming inbetween dating and friend option, but i want only one comma ie dating, Networking in table.

    This is the code :::::::

    <input type="checkbox" name="checkbox1" value="Dating" />Dating

    <input type="checkbox" name="checkbox2" value="Serious Relationships" />Serious Relationships

    <input type="checkbox" name="checkbox3" value="Friends" />Friends
    <input type="checkbox" name="checkbox4" value="Networking" /> Networking


    I am using this variable::::::::::;
    $checkbox1=$_POST['checkbox1'];//varible for dating
    $checkbox2=$_POST['checkbox2'];//varible for serious ralationship
    $checkbox3=$_POST['checkbox3'];//varible for friends
    $checkbox4=$_POST['checkbox4'];//varible for networking
    $final=$checkbox1.",".$checkbox1.",".$checkbox1.",".$checkbox1;
    $qry_ins="update register_dtl set gender='$gender',dob='$dob',occupation='$occupation',city='$city',country='$country',region='$region',postal_code='$postalcode',ethnicity='$ethnicity',bodytype= '$bodytype',height='$height',i_am_here_for='$final' where uname='".$_SESSION['username']."'";
    $rs_ins=mysql_query($qry_ins) or die("error:". mysql_error());

    Can anyone will help me it is urgent

    Thanks & Regards

    Ranjan

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Have a check like the following immediately you place values in the checkbox variables

    Code:
    $final = ""; //initialize this variable before starting the following condition checking
    if($checkbox1 != "")
    	$final = $final . $checkbox1;
    
    if($checkbox2 != "" && $final != "")
    	$final = $final .",". $checkbox2;
    else
    	$final = $final . $checkbox2;
    	
    if($checkbox3 != "" && $final != "")
    	$final = $final .",". $checkbox3;
    else
    	$final = $final .$checkbox3;
    	
    if($checkbox4 != "" && $final != "")
    	$final = $final .",". $checkbox4;
    else
    	$final = $final . $checkbox4;
    After this checking store the $final in the appropriate field in your table.

    Another thing RDBMS packages recommend to store atomic values in the table field in your case you are combining two values using a comma and storing it in a single field.

  3. #3
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thanks

    Hi

    Its working . Thanks for ur co-operation.

    Thanks & Regards
    Ranjan

  4. #4
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default select checkbox value from database, Urgent

    Hi

    Its working fine. But afer sending the value from database, i want to select the value from databse table. My problem is that, i want the select value should be checked in the checkbox....How to do , Help me...

    Example: I have inserted the dating, networking into database table. after that i want to dating, networking checkbox should be check after writing the select query.


    <td align="left" valign="middle" bgcolor="#A3C5E0" class="blacktext">
    <p>
    <input name="checkbox1" type="checkbox" value="Dating" />
    <span id="ctl00_ctl00_Main_ProfileEditContent_editBasicInfo_hereForCheckBoxList" class="items">
    <label for="ctl00_ctl00_Main_ProfileEditContent_editBasicInfo_hereForCheckBoxList_0">Dating</label>
    </span> </p>
    <p>
    <input type="checkbox" name="checkbox2" value="Serious
    Relationships" />
    <span id="ctl00_ctl00_Main_ProfileEditContent_editBasicInfo_hereForCheckBoxList" class="items">
    <label for="ctl00_ctl00_Main_ProfileEditContent_editBasicInfo_hereForCheckBoxList_1">Serious
    Relationships</label>
    </span> </p>
    <p>
    <input type="checkbox" name="checkbox3" value="Friends" />
    <span id="ctl00_ctl00_Main_ProfileEditContent_editBasicInfo_hereForCheckBoxList" class="items">Friends</span>
    </p>
    <p>
    <input type="checkbox" name="checkbox4" value="Networking" />
    Networking </p></td>




    sql query::::::::::::::::::::::::




    if(isset($_REQUEST['occupation']) && $_REQUEST['occupation']!="")
    {
    $gender=$_POST['radiobutton'];
    $dob=$_POST['dob'];
    $occupation=$_POST['occupation'];
    $city=$_POST['city'];
    $country=$_POST['country_code'];
    $region=$_POST['region'];
    $postalcode=$_POST['postalcode'];
    $ethnicity=$_POST['ethnicity'];
    $bodytype=$_POST['bodytype'];
    $height=$_POST['height'];
    $checkbox=$_POST['checkbox'];


    $checkbox1=$_POST['checkbox1'];//varible for dating
    $checkbox2=$_POST['checkbox2'];//varible for serious ralationship
    $checkbox3=$_POST['checkbox3'];//varible for friends
    $checkbox4=$_POST['checkbox4'];//varible for networking
    //$final=$checkbox1.",".$checkbox1.",".$checkbox1.",".$checkbox1;
    /*
    if ($checkbox1)
    {
    $final= $checkbox1;
    }
    elseif($checkbox1 && $checkbox2 )
    {
    $final= $checkbox1.",".$checkbox2;
    }
    elseif($checkbox1 && $checkbox2 )
    {


    }
    */
    $final = ""; //initialize this variable before starting the following condition checking
    if($checkbox1 != "")
    $final = $final . $checkbox1;

    if($checkbox2 != "" && $final != "")
    $final = $final .",". $checkbox2;
    else
    $final = $final . $checkbox2;

    if($checkbox3 != "" && $final != "")
    $final = $final .",". $checkbox3;
    else
    $final = $final .$checkbox3;

    if($checkbox4 != "" && $final != "")
    $final = $final .",". $checkbox4;
    else
    $final = $final . $checkbox4;

    $qry_ins="update register_dtl set gender='$gender',dob='$dob',occupation='$occupation',city='$city',country='$country',region='$region',postal_code='$postalcode',ethnicity='$ethnicity',bodytype= '$bodytype',height='$height',i_am_here_for='$final' where uname='".$_SESSION['username']."'";
    $rs_ins=mysql_query($qry_ins) or die("error:". mysql_error());

    }


    Thanks & regards

    Ranjan

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
  •