send multi checkbox php mysql

How can I change checkbox name to unique then I can handle it to insert to database and also when I click bottom Checkall it will check all box
<?php require_once('Connections/Thaymay.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_Thaymay, $Thaymay);
$query_RsActivitynoteMem = "Select an.id,   m1.Sname,   m1.Ssurname,   an.idactivity,   m2.Sname AS kname From activitynote an Join   member m1 On an.idmemberref = m1.idmember Join   member m2 On an.manaferid = m2.idmember Order By an.id    ";
$RsActivitynoteMem = mysql_query($query_RsActivitynoteMem, $Thaymay) or die(mysql_error());
$row_RsActivitynoteMem = mysql_fetch_assoc($RsActivitynoteMem);
$totalRows_RsActivitynoteMem = mysql_num_rows($RsActivitynoteMem);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>¿¿¿¿¿¿¿</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- 	
// by Nannette Thacker
// http://www.shiningstar.net
// This script checks and unchecks boxes on a form
// Checks and unchecks unlimited number in the group...
// Pass the Checkbox group name...
// call buttons as so:
// <input type=button name="CheckAll"   value="Check All"
	//onClick="checkAll(document.myform.list)">
// <input type=button name="UnCheckAll" value="Uncheck All"
	//onClick="uncheckAll(document.myform.list)">
// -->

<!-- Begin
function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
//  End -->
</script>


</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="627" border="1">
    <tr>
      <td width="20">&nbsp;</td>
      <td width="198">&nbsp;</td>
      <td width="20">&nbsp;</td>
      <td width="179">&nbsp;</td>
      <td width="4">&nbsp;</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><input name="checkbox" type="checkbox" id="<?php echo $row_RsActivitynoteMem['id']; ?>" value="<?php echo $row_RsActivitynoteMem['id']; ?>" />
        <label for="checkbox"></label></td>
        <td><?php echo $row_RsActivitynoteMem['Sname']; ?> <?php echo $row_RsActivitynoteMem['Ssurname']; ?></td>
        <td width="20"><?php echo $row_RsActivitynoteMem['idactivity']; ?></td>
        <td><?php echo $row_RsActivitynoteMem['kname']; ?></td>
        <td>&nbsp;</td>
      </tr>
      <?php } while ($row_RsActivitynoteMem = mysql_fetch_assoc($RsActivitynoteMem)); ?>
<tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td width="20">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <input type="button" name="CheckAll" value="Check All"
onClick="checkAll(document.form1.checkbox)">
<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckAll(document.form1.checkbox)">
<br>

</form>
</body>
</html>
<?php
mysql_free_result($RsActivitynoteMem);
?>

Open in new window

teeraAsked:
Who is Participating?
 
AverittegConnect With a Mentor Commented:
You can use jquery which can search the entire form and check all of the checkboxes it finds.

Just include this to pull in the jquery library:
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>

Add the "checkbox" class to each input checkbox.

And then to search through the form you have above:
<script language="javascript">
function checkAll()
{
      $("#form1 .checkbox").each( function() {
                        $(this).attr("checked",status);
      })
}

function uncheckAll()
{
      $("#form1 .checkbox").each( function() {
                        $(this).removeAttr("checked");
      })
}

This will work for all inputs in your form.
0
 
AverittegCommented:
An option you can do for the unique id number, you can select the record ID to put in as the checkbox ID. I see you are using an [id] as it is, but it will only work if it's unique else one box checked could result in multiple findings when searched via javascript. This will give you a way to localize each selection and know which options you're working with.
To cycle through the form to find out which id or records you're dealing with, you could use a similar fashion (.each()) in jquery and build your responses to pass over to your php server.
0
 
Ray PaseurConnect With a Mentor Commented:
@teera, it looks like you are trying to learn PHP programming by reading DreamWeaver code.  That is like looking at an apple pie and hoping it will teach you how to cook.  Instead, drop what you're doing and get this excellent little book.  It is very readable with great examples.  Now in its fourth printing, it has been a permanent part of my professional library since Edition One.
http://www.sitepoint.com/books/phpmysql4/

This article will answer some of your questions about checkboxes...
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.