View Full Version : checkbox should be check, after fetching the value from database

05-02-2007, 11:57 AM
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 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.It coming like that only .

This is the Problem::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...

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::::::::::;
$final = ""; //initialize this variable before starting the following condition checking
if($checkbox1 != "")
$final = $final . $checkbox1;

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

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

if($checkbox4 != "" && $final != "")
$final = $final .",". $checkbox4;
$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());

Can anyone will help me it is urgent

Thanks & Regards