select the value from database using checkbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
purnendu231172
Forum Newbie
Posts: 11
Joined: Mon Apr 16, 2007 6:29 am

select the value from database using checkbox

Post by purnendu231172 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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.


[syntax="html"]<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::::::::::::::::::::::::[/syntax]

Code: Select all

<?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


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You can try something like this:

Code: Select all

<input name="checkbox1" type="checkbox" value="Dating"
<?php
if ($row['checkbox1']) {
     echo ' checked="checked"';
}
?>
/>
(#10850)
Post Reply