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
https://forums.phpfreaks.com/topic/44673-checkbox-in-php/
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
https://forums.phpfreaks.com/topic/44673-checkbox-in-php/#findComment-216920
Share on other sites

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.