Some form fields will still submit a value, even if that value is an empty string. So to carry out accurate conditionals, you have to check for non-empty values. Also, If your going to the trouble of converting post vars to short vars, may as well use em.
How does this work for you?
PHP Code:
include "conn.php";
if(isset($_POST)) {
//long to short
$id = (!empty($_POST['id'])) ? $_POST['id'] : false;
$type = (!empty($_POST['type'])) ? $_POST['type'] : false;
$amount = (!empty($_POST['amount'])) ? $_POST['amount'] : false;
$pdate = (!empty($_POST['pdate'])) ? $_POST['pdate'] : false;
$famount = (!empty($_POST['famount'])) ? $_POST['famount'] : false;
$fdate = (!empty($_POST['fdate'])) ? $_POST['fdate'] : false;
$final_payment = 0;
if( $famount && $famount > 0 ){
$final = "Select payid,id,famount,fdate from pay_tbl where id = '$id' and fdate != 0000-00-00 and type= '$type'";
$query = mysql_query($final);
$final_payment = mysql_num_rows($query);
}
if( $final_payment > 0 ) {
echo "<h3>";
echo "Error! Final Payment has been Posted! Please Check Date and Delete previous Final Payment !";
echo "</h3>";
} elseif ( $amount && $famount ) {
echo "<h4>";
print "Error you can't post a regular payment and final payment at the same time! Use back button to correct this problem!";
echo "</h4>";
} elseif ( $amount && $pdate ) {
$sql = "INSERT INTO pay_tbl (id,type,amount,pdate) values('$id','$type','$amount','$pdate')";
$query = mysql_query($sql) or die("Could not insert");
header("location:community.php");
exit;
} elseif ( $famount && $fdate ){
$sql = "INSERT INTO pay_tbl (id,type,famount,fdate) values('$id','$type','$famount','$fdate')";
$query = mysql_query($sql) or die("Could not insert");
header("location:community.php");
exit;
} else {
echo "Error! To Post Payments you must have a Date and Amount! Use Back Button to Correct";
}
}//end post processing