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