send value into database table using ckeckbox

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

send value into database table using ckeckbox

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]


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

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

Code: Select all

$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


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]
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Post by afbase »

Just kinda off the top of my head

Code: Select all

/*not sure if this helps*/
if (checkbox1 == ""){
$final = "";
}
else{
$final = $_POST['checkbox1'];
}
if ($checkbox2 =""){
}
else {
$final .= ", ".$_POST['checkbox2'];
}
// i think you get the idea
It seems your a newb to the forum, try reading that Forum Tour post.
Zu
Forum Commoner
Posts: 33
Joined: Wed Dec 06, 2006 4:21 am

Post by Zu »

I would probably advice against afbase method. The reason being that if you ever extended the script you would need to add a load more code. Not to mention it is very repetitive.

Store the names of the elements in an array, loop through that array building the query as you go.
Post Reply