Hey everyone...take a look at the script below because I am in need of some serious help π Right now I am stuck. The script is supposed to loop through information submitted from a form (5 rows of 3 of the same variables, i.e. one <tr></tr> copied 5 times). Variable names are changed to be 'cinstitution1','cinstitution2' etc up to 5. What I need to do is validate EACH of these BEFORE the individual statement gets inserted. Any ideas? Thanks all, this would be a big help!
<?
$nocash=$_POST['nocash'];
if ($nocash==1) {
$cquery=("INSERT INTO u_cash (user_id,id,institution,accountnumber,value,ownership) VALUES ('".$_SESSION['user_id']."','','','','','')");
if (!(@ mysql_query($cquery, $connection))) {
showerror();
die('Query Failed');
}
}
else{
for ($i=1; $i<=5;$i++){
$cid=$i;
$cinstitution[$i]=addslashes($_POST['cinstitution'.$i]);
$cacctnumber[$i]=addslashes($_POST['cacctnumber'.$i]);
$cvalue[$i]=addslashes($_POST['cvalue'.$i]);
$cownership[$i]=addslashes($_POST['cownership'.$i]);
if (!empty($cinstitution[$i]) || !empty($cacctnumber[$i]) || !empty($cvalue[$i]) || !empty($cownership[$i])) {
if (empty($cinstitution)) $errors .= "Please enter the name of the instution for cash account #".$i.".\n";
if (empty($cacctnumber)) $errors .= "Please enter the account number for cash account #".$i.".\n";
if (empty($cvalue)) $errors .= "Please enter the value of cash account #".$i.".\n";
if (empty($cownership)) $errors .= "Please enter the name of the owner of cash account #".$i.".\n";
}
if (empty($errors)) {
$cquery=("INSERT INTO u_cash (user_id,id,institution,acctnumber,value,ownership) VALUES ('".$_SESSION['user_id']."','".$i."','".$cinstitution[$i]."','".$cacctnumber[$i]."','".$cvalue[$i]."','".$cownership[$i]."')");
if (!(@ mysql_query($cquery, $connection))) {
showerror();
die('Query Failed');
}
}
}
}
?>