Jump to content

PHP and Checkboxes..


techiefreak05

Recommended Posts

They have never been my strong suit...

I have this script, that gets the amount of employees from the DB, then check ot see if the number of check boxes that are CHECKED are equal to the number of employees. Basically each employee needs to be checked..

 

It DOES display "Verified", but the part where it tells them to verify all employees, does not show up.

Anytihng wrong?

 

<?php
$loc=$_SESSION["admin_loc"];

$sql="SELECT * FROM employees WHERE Location = '$loc' ORDER BY location DESC";
$doQuery=mysql_query($sql);
$getEmpCount=mysql_num_rows($dbQuery);

if($_POST["doFinal"]){

$emp=$_POST['emp'];
	foreach ($emp as $empCheck)
	{
		if($empCheck<$getEmpCount){
			echo "<center>You must verify <b>all</b> employees before finalizing.</center>";
		}else{
			echo "<center>Verified.</center>";
		}
	}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/90223-php-and-checkboxes/
Share on other sites

check boxes only return info if it's checked

otherwise ya dun get anything from the checkbox

 

below is a sample script to show you what i mean.

<?php

if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_POST['cb']))
{
	$cbv=$_POST['cb'];
	echo " Checkboxes checked =" . implode(',',$cbv) . "";
}
}
?>    
<html>
<body>
  <form method="POST">
  <INPUT TYPE='checkbox' name='cb[]' value='0'>  
  <INPUT TYPE='checkbox' name='cb[]' value='1'>  
  <INPUT TYPE='checkbox' name='cb[]' value='2'>  
  <INPUT TYPE='checkbox' name='cb[]' value='3'>  
  <INPUT TYPE='checkbox' name='cb[]' value='4'>
  <INPUT type="submit">
  </FORM>
</body>
</html>

 

but since u need all the values that checkboxes contain.

your best bet is add a hidden field with the list

 

<INPUT TYPE='hidden' NAME='valid' VALUE='<?=implode('|',$myarrayofvalidids)?>'>

 

than explode and compare it against te values returned by the checkboxes

Link to comment
https://forums.phpfreaks.com/topic/90223-php-and-checkboxes/#findComment-462637
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.