mwm
08-27-2007, 02:19 PM
I have a script to check to see if pamount and pdate are set before those variable are inserted into the db. My problem is that if the pamount is left blank and the pdate is not it still inserts the pdate. I have tried to change the script to || instead of && but no help. Please let me know where I went wrong.
Thanks
<?
//session_start();
include "conn.php";
$id=$_POST['id'];
$type=$_POST['type'];
$amount=$_POST['amount'];
$pdate=$_POST['pdate'];
$famount=$_POST['famount'];
$fdate=$_POST['fdate'];
/*
echo "<pre>";
print_r ($_POST);
echo "</pre>";
*/
if($_POST['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);
}
if(mysql_num_rows($query) >0) {
echo "<h3>";
echo "Error! Final Payment has been Posted! Please Check Date and Delete previous Final Payment !";
echo "</h3>";
}
elseif (($_POST['amount']) && ($_POST['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(isset($_POST['amount']) && ($_POST['pdate'])) {
$query = "INSERT INTO pay_tbl (id,type,amount,pdate) values('$id','$type','$amount','$pdate')";
$result = mysql_query($query) or die("Could not insert");
header("location:community.php");
}
elseif (isset($_POST['famount']) && ($_POST['fdate'])){
$query = "INSERT INTO pay_tbl (id,type,famount,fdate) values('$id','$type','$famount','$fdate')";
$result = mysql_query($query) or die("Could not insert");
header("location:community.php");
} else {
echo "Error! To Post Payments you must have a Date and Amount! Use Back Button to Correct";
}
?>
Thanks
<?
//session_start();
include "conn.php";
$id=$_POST['id'];
$type=$_POST['type'];
$amount=$_POST['amount'];
$pdate=$_POST['pdate'];
$famount=$_POST['famount'];
$fdate=$_POST['fdate'];
/*
echo "<pre>";
print_r ($_POST);
echo "</pre>";
*/
if($_POST['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);
}
if(mysql_num_rows($query) >0) {
echo "<h3>";
echo "Error! Final Payment has been Posted! Please Check Date and Delete previous Final Payment !";
echo "</h3>";
}
elseif (($_POST['amount']) && ($_POST['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(isset($_POST['amount']) && ($_POST['pdate'])) {
$query = "INSERT INTO pay_tbl (id,type,amount,pdate) values('$id','$type','$amount','$pdate')";
$result = mysql_query($query) or die("Could not insert");
header("location:community.php");
}
elseif (isset($_POST['famount']) && ($_POST['fdate'])){
$query = "INSERT INTO pay_tbl (id,type,famount,fdate) values('$id','$type','$famount','$fdate')";
$result = mysql_query($query) or die("Could not insert");
header("location:community.php");
} else {
echo "Error! To Post Payments you must have a Date and Amount! Use Back Button to Correct";
}
?>