The code below is part of a script that accepts user input from a form. What I WANT it to do is only add values to the array if the variables arent empty...and if they are empty then it should skip it. Right now this works perfectly but if only values for the first row are entered it will still generate 5 array values when i want it to only generate 1. Any ideas? Thanks 🙂
$tanarray = array();
for ($i=1; $i<=5;$i++){
//$notan=addslashes($_POST['notan'];
$tanid=$i;
$tandescription[$i]=addslashes($_POST['tandescription'.$i]);
$tanvalue[$i]=addslashes($_POST['tanvalue'.$i]);
$tanownership[$i]=addslashes($_POST['tanownership'.$i]);
if ($i==1) {
if (empty($tandescription[$i])) $errors .= "Please enter a description of asset #".$i.".\n";
if (empty($tanvalue[$i])) $errors .= "Please enter a dollar value of asset #".$i.".\n";
if (empty($tanownership[$i])) $errors .= "Please enter whether or not asset #".$i." is owned.\n";
}
else {
if (!empty($tandescription[$i]) || !empty($tanvalue[$i]) || !empty($tanownership[$i]) && ($i!=1)) {
if (empty($tandescription[$i])) $errors .= "Please enter a description of asset #".$i.".\n";
if (empty($tanvalue[$i])) $errors .= "Please enter a dollar value of asset #".$i.".\n";
if (empty($tanownership[$i])) $errors .= "Please enter whether or not asset #".$i." is owned.\n";
}
}
if (empty($errors)) {
$tanarray[$i]="INSERT INTO u_tanproperty (user_id,id,description,value,ownership) VALUES ('".$_SESSION['user_id']."','".$i."','".$tandescription[$i]."','".$tanvalue[$i]."','".$tanownership[$i]."')";
}
}