Hi,
This is the code that works for validating but it doesnt enter it into the database, it just puts out 0000-00-00. I know the code doesnt have to be this long, but its the only way i got it working.
As you can probably tell, the date input fields are three seperate ones.
How can i make sure that it checks if the date is right and then puts it in the database correctly?
Any help?
if ((isset($_POST["update"])) == "NW") {
//Prepared date variables
$DPd = $_POST['DPd'];
$DPm = $_POST['DPm'];
$DPy = $_POST['DPy'];
//Repaired date variables
$DRd = $_POST['DRd'];
$DRm = $_POST['DRm'];
$DRy = $_POST['DRy'];
//Failure date variables
$DFd = $_POST['DFd'];
$DFm = $_POST['DFm'];
$DFy = $_POST['DFy'];
//Other variables
$PPN = $_POST['PPN'];
$Model = $_POST['Model'];
$Serial = $_POST['Serial'];
$EN = $_POST['EN'];
$Hours = $_POST['Hours'];
$Customer = $_POST['Customer'];
$Application = $_POST['Application'];
$Material = $_POST['Material'];
$JL = $_POST['JL'];
$status = $_POST['status'];
//All fields required validation
//foreach ($_POST as $key => $value) {
//$value = trim($value);
//if (!$value) {$empty = 1;}
//$$key = $value;
//}
//Validate prepared date
if (!ctype_digit($DPd)) {$dpderror = 1;}
if (!ctype_digit($DPm)) {$dpmerror = 1;}
if (!ctype_digit($DPy)) {$dpyerror = 1;}
//Validate repaired date
if (!ctype_digit($DRd)) {$drderror = 1;}
if (!ctype_digit($DRm)) {$drmerror = 1;}
if (!ctype_digit($DRy)) {$dryerror = 1;}
//Validate failure date
if (!ctype_digit($DFd)) {$drfderror = 1;}
if (!ctype_digit($DFm)) {$dfmerror = 1;}
if (!ctype_digit($DFy)) {$dfyerror = 1;}
//Other validations
if (!ctype_alnum($PPN)) {$ppnerror = 1;}
if (!ctype_alnum($Model)) {$merror = 1;}
if (!ctype_alnum($Serial)) {$serror = 1;}
if (!ctype_alnum($EN)) {$enerror = 1;}
if (!ctype_digit($Hours)){$herror = 1;}
if (!ctype_alnum($Customer)) {$cerror = 1;}
if (!ctype_alnum($Application)) {$aerror = 1;}
if (!ctype_alnum($Material)) {$maerror = 1;}
if (!ctype_alnum($JL)) {$jlerror = 1;}
//Large if statement
if ($ppnerror == 1 || $merror == 1 || $serror == 1 || $enerror == 1 || $herror == 1
|| $cerror == 1 || $aerror == 1 || $maerror == 1 || $jlerror == 1 || $dpderror == 1 || $dpmerror == 1 || $dpyerror == 1
|| $drderror == 1 || $drmerror == 1 || $dryerror == 1 || $dfderror == 1 || $dfmerror == 1 || $dfyerror == 1){
$message = 1;
//$URL="dwc.php";
//header ("Location: $URL");
}else{
$datedp = "$DPd-$DPm-$DPy";
$datedr = "$DRd-$DRm-$DRy";
$datedf = "$DFd-$DFm-$DFy";
$update_w = "UPDATE Warrants SET DPrepared='$datedp', DRepared='$datedr', DFailure='$datedf', PPartnumber='$PPN', Model='$Model', FullSN='$Serial',
ENumber='$EN', Hours='$Hours', Customer='$Customer', Application='$Application', Material='$Material', JLocation='$JL', Status='$status'
WHERE RefNumber='$ref_value'";
$Result = mysql_query($update_w, $localhost) or die(mysql_error());
$update_w = "dwcc.php";
if (isset($_SERVER['QUERY_STRING'])) {
$update_w .= (strpos($update_w, '?')) ? "&" : "?";
$update_w .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $update_w));
}
}
Thanks for any help.