Forum Moderators: coopster
The form contains checkboxes and if they are not submited it throws the count off.
Is there a way to account for the checkboxes?
if(isset($_POST['MM_insert'])/* &&!empty($_POST['STAFFNUMBER'])*/){
$_POST['Established'] == 'on'? $est = '1' : $est = '0';
$_POST['Employee'] == 'on'? $emp = '1' : $emp = '0';$post_values = array_values($_POST); // Gets values of the array
$post_keys = array_keys($_POST);
$x <= 0;
// print_r($post_keys);
$post_count = count($post_values); // counts values in the array
$var_type_cast = array('text','number','date','varchar','hyperlink'); // variable type
$required = array(0,1,2,7,9,10,15); // required variables
$required_values = array_values($required);
$required_count = count($required); // count required variables
// print_r($required_values);
for($i = 0; $i < $post_count; $i++){ // Builds an array that can be checked later
if(empty($post_values[$i])){
$ans[] = 'yes';
}
else{
$ans[] ='no';
}
}
$b = $ans;
$c = array_combine($post_keys, $b);
// print_r($c);
$newvalues = array_values($required); // Gets values of the array
for($i = 0; $i < $required_count; $i++){ // Builds an array
if($c[$i] == 'yes'){
$first_check = 'yes';
}
}
$post_values = array_values($_POST);
$x = 0;
while($x <= count($_POST)){ // replace all ' with ''
$replace[] = eregi_replace("'", "''", stripslashes($post_values[$x++]));
}
$rsltcombine = array_combine($_POST, $replace);
$rsInsert = "Sql insert";
$insert = new Get_Sql(); $insert_rslts = $insert->SqlSingle($rsInsert);
header("Location: index.php");
}
Thanks
fintan.
name="box[]" as opposed to name="box") If
box[], then you've got $_POST["box"] as a natural array ($_POST["box"][0]). Otherwise, $_POST["box"] will only reference the last box= element in the $_POST array. Are you having trouble handling
$_POST["box"] elements? Or is it just messing with your $post_count?
box[] method because that would give you 1 element in the $_POST array to deal with instead of trying to account for all of the individual checkboxes. If only one box or all of the boxes are checked, the array exists as a single element (with multiple internal elements). If none are checked, it doesn't exist. I thought it might help ... ;)