Jump to content

select the value from database using checkbox


purnendu2311

Recommended Posts

select the value from database using checkbox

« on: Today at 09:25:47 AM »

Reply with quote Modify message

Hi

 

Afer sending the value from database, i want to select the value from databse table. My problem is that, i want the selected 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::::::::::::::::::::::::

<?php

session_start();

include 'connection.php';

$sqry="select * from register_dtl where uname='".$_SESSION['username']."'";

$rs_s=mysql_query($sqry) or die("error:". mysql_error());

$no_of_rows_s=mysql_num_rows($rs_s);

$row_sel=mysql_fetch_assoc($rs_s);

$gender1=$row_sel['gender'];

$dob1=$row_sel['dob'];

$occupation1=$row_sel['occupation'];

$city1=$row_sel['city'];

$country1=$row_sel['country'];

$region1=$row_sel['region'];

$postal_code1=$row_sel['postal_code'];

$ethnicity1=$row_sel['ethnicity'];

$bodytype1=$row_sel['bodytype'];

$height1=$row_sel['height'];

$i_am_here_for1=$row_sel['i_am_here_for'];

 

 

 

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

Thanks Edit/Delete Message

in the form there, simply put this:

 



<input type="radio" name="select" value="1" <?php if ($select==1): ?> checked <?php endif; ?>> 1;

<input type="radio" name="select" value="2" <?php if ($select==2): ?> checked <?php endif; ?>> 2;
	  	       




 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.