Hi to all SitePoint Members,
I have successfuly developed a small CMS to manage some records. Now I wana re-develop this CMS by improving its codes. This time i am focusing on “Code Shortening”
Friends please suggest me ways how can I shorten this code
<?php
require_once("config.php");
require_once("functions.php");
require_once("startsession.php");
$sr_no = (!isset($_POST['sr_no']) || trim($_POST['sr_no']) == "") ? die ('ENTER SERIAL NO') :
mysql_real_escape_string(trim($_POST['sr_no']));
$bill_no = (!isset($_POST['bill_no']) || trim($_POST['bill_no']) == "") ? die ('ENTER BILL NO') :
mysql_real_escape_string(trim($_POST['bill_no']));
$bill_date = (!isset($_POST['bill_date']) || trim($_POST['bill_date']) == "") ? die ('ENTER BILL DATE') :
parseDate(mysql_real_escape_string(trim($_POST['bill_date'])));
$ref_no = (!isset($_POST['ref_no']) || trim($_POST['ref_no']) == "") ? die ('ENTER REF NO') :
mysql_real_escape_string(trim($_POST['ref_no']));
$vehicle = (!isset($_POST['vehicle']) || trim($_POST['vehicle']) == "") ? die ('ENTER CLAIM OF') :
mysql_real_escape_string(trim($_POST['vehicle']));
$insured_name = (!isset($_POST['insured_name']) || trim($_POST['insured_name']) == "") ? die ('ENTER INSURED NAME') :
mysql_real_escape_string(trim($_POST['insured_name']));
$vehicle_no = (!isset($_POST['vehicle_no']) || trim($_POST['vehicle_no']) == "") ? die ('ENTER VEHICLE NO') :
mysql_real_escape_string(trim($_POST['vehicle_no']));
$date_of_loss = (!isset($_POST['date_of_loss']) || trim($_POST['date_of_loss']) == "") ? die ('ENTER DATE OF LOSS') :
parseDate(mysql_real_escape_string(trim($_POST['date_of_loss'])));
$date_of_survey = (!isset($_POST['date_of_survey']) || trim($_POST['date_of_survey']) == "") ? die ('ENTER DATE OF SURVEY') :
parseDate(mysql_real_escape_string(trim($_POST['date_of_survey'])));
$claim_no = (!isset($_POST['claim_no']) || trim($_POST['claim_no']) == "") ? die ('ENTER CLAIM NO') :
mysql_real_escape_string(trim($_POST['claim_no']));
$policy_no = (!isset($_POST['policy_no']) || trim($_POST['policy_no']) == "") ? die ('ENTER POLICY NO') :
mysql_real_escape_string(trim($_POST['policy_no']));
$insurers = (!isset($_POST['insurers']) || trim($_POST['insurers']) == "") ? die ('ENTER INSURANCE COMPANY NAME') :
mysql_real_escape_string(trim($_POST['insurers']));
$issuing_office = (!isset($_POST['issuing_office']) || trim($_POST['issuing_office']) == "") ? die ('ENTER INSURANCE POLICY ISSUING OFFICE') :
mysql_real_escape_string(trim($_POST['issuing_office']));
$survey_fees = (!isset($_POST['survey_fees']) || !is_numeric($_POST['survey_fees'])) ? die ('ENTER SURVEY FEES AMOUNT (numeric value)') :
mysql_real_escape_string(trim($_POST['survey_fees']));
$type_of_report = (!isset($_POST['type_of_report']) || trim($_POST['type_of_report']) == "") ? die ('ENTER TYPE OF REPORT') :
mysql_real_escape_string(trim($_POST['type_of_report']));
$remarks = (!isset($_POST['remarks']) || trim($_POST['remarks']) == "") ? die ('ENTER REMARKS') :
mysql_real_escape_string(trim($_POST['remarks']));
$user_name = $_SESSION['username'];
$query = "INSERT INTO ledger (sr_no,bill_no,bill_date,ref_no,insured_name,vehicle,vehicle_no,date_of_loss,date_of_survey,type_of_report,claim_no,policy_no,insurers,issuing_office,survey_fees,remarks,now,user)
VALUES ('NULL','$bill_no','$bill_date','$ref_no','$insured_name','$vehicle','$vehicle_no','$date_of_loss','$date_of_survey','$type_of_report','$claim_no','$policy_no','$insurers','$issuing_office','$survey_fees','$remarks',NOW(),'$user_name')";
if (!mysql_query($query,$con))
{
die('Could not update database' . mysql_error());
}
?>