Jump to content

checkbox in php


kadamsurekha

Recommended Posts

hello!

 

i hav a dynamic checkbox array. i want to know, out of all which are selected and if selected then i am inserting the selected checkbox value in the table field.

 

my code is as follows:-

 

$no=0;

$friendname= $_POST['friendname'];

$storecount=$_POST['storeid'];

while($no<$storecount)

{

if($friendname[$no])

{

$sql = "INSERT INTO groupfriends (groupid, username) VALUES ('$stid[$no]', '$friendname[$no]')";

 

$result = mysql_query($sql) or die('Query

 

failed. ' . mysql_error());

}

$no=$no+1;

}

 

 

the code adds all the checkboxes. i want to add only those checkboxes which r selected.

 

can any1 help me plse???????

 

thx n regards

Link to comment
Share on other sites

call this javascript on the click event of the submit button

 

                                 

 function MM_callJS()  
                                                  { 
                                				document.form1.chkIds.value=document.form1.links.value
							for (i=0; i<document.form1.links.length; i++){

                  			  if (document.form1.links[i].checked==true)
				       {
														    document.form1.chkIds.value=document.form1.chkIds.value+","+document.form1.links[i].value

							  }   

								 }
					         

                           return true;
							  }

 

In this example te checkbox has a name 'links' and a hidden field named chkIds. on form submit the values of the selected boxes are passed to the hidden field.

This value neds to be exploded with ','

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.