I really need help at this moment. I am trying to make an application that records cash/bank payments.
I have a table called 'cashbook'. It stores data about cash/bank payments. It has 8 columns:
id (stores transaction id)
enter code here
tdate (stores transaction date
chequeno (stores cheque number, if the payment is made by cheque)
originator (stores the name of the person to whom payment is made)
cr_amount (stores the amount of cash/bank payment)
tclass (stores the information about the class of transaction)
pmode (stores the mode of transaction-cash or bank)
payer (stores the name of the person making the payment)
I am making a program that will insert data into specific columns of the 'cashbook' table when certain conditions are met. I have defined 4 conditions on which to record cash/bank payments.
Below is the html form that is used to collect data:
$(document).ready(function(){
$('#designation').on('change', function(){
if ( this.value == '1')
{
$("#supp").show();
$("#paye").hide();
}
else if ( this.value == '2')
{
$("#paye").show();
$("#supp").hide();
}
else
{
$("#supp").hide();
}
});
});
$(document).ready(function(){
$('#pmoder').on('change', function(){
if ( this.value == '2')
{
$("#chequeno").show();
}
else
{
$("#chequeno").hide();
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form role="form" method="post" action="registercash.php">
<div class="form-group">
<label>Date</label>
<input class="form-control" name="tdate" type="date">
</div>
<div class="form-group">
<label>Mode of Payment</label>
<select class="form-control" id="pmoder" name="pmode">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="form-group" id="chequeno" style="display: none;">
<label>Cheque no</label>
<input class="form-control" name="chequeno" >
</textarea>
</div>
<div class="form-group" >
<label>Amount</label>
<input class="form-control" name="tamount" >
</textarea>
</div>
<div class="form-group">
<label>Designation / Supplier</label>
<select class="form-control" id='designation' name="desig">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="form-group" id="paye" style="display: none;">
<label>Name of Payee</label>
<input class="form-control" name="payeename" >
</textarea>
</div>
<div class="form-group" id='supp' style="display: none;">
<label>Select Supplier</label>
<select class="form-control" name="suppliername">
<option>Ministry of Trade and Industry</option>
<option>Okaikwei North Municipal Assembly</option>
</select>
</div>
<div class="form-group">
<label>Class</label>
<select class="form-control" name="tclass">
<option>Personnel Emoluments</option>
<option>Materials & Office consumables</option>
<option>Serminars & Conferences</option>
</select>
</div>
<button type="submit" name="Submit" class="btn btn-default">Record</button>
</form>
Below is the script that adds data to the 'cashbook' table:
<html>
<head>
<title>Add Data</title>
</head>
<body>
<?php
//including the database connection file
include_once("config.php");
$keyb = "";
$keya = "";
$chequeno = "";
$keyc = "";
$payeename = "";
$suppliername = "";
$tdate = "";
$tclass = "";
$tamount = "";
if(isset($_POST['Submit'])) {
$keyb = mysqli_real_escape_string($mysqli, $_POST['pmode']);
$chequeno = mysqli_real_escape_string($mysqli, $_POST['chequeno']);
$keyc = mysqli_real_escape_string($mysqli, $_POST['desig']);
$payeename = mysqli_real_escape_string($mysqli, $_POST['payeename']);
$suppliername = mysqli_real_escape_string($mysqli, $_POST['suppliername']);
$tdate = mysqli_real_escape_string($mysqli, $_POST['tdate']);
$tclass = mysqli_real_escape_string($mysqli, $_POST['tclass']);
$tamount = mysqli_real_escape_string($mysqli, $_POST['tamount']);
}
if(empty($keyb) || empty($keyc)|| empty($chequeno)|| empty($payeename)|| empty($suppliername)|| empty($tdate)|| empty($tclass)|| empty($tamount)) {
if(empty($keyb)) {
echo "<font color='red'>Payment mode is empty.</font<br/>";
}
if(empty($keyc)) {
echo "<font color='red'>Designation is empty.</font><br/>";
}
if(empty($tdate)) {
echo "<font color='red'>Transaction date is empty.</font><br/>";
}
if(empty($tclass)) {
echo "<font color='red'>Transaction class is empty.</font><br/>";
}
if(empty($tamount)) {
echo "<font color='red'>Transaction amount is empty.</font><br/>";
}
} elseif ($keyb=="1" && $keyc =="2"){
$result = mysqli_query($mysqli, "INSERT INTO cashbook(tdate, originator, cr_amount, tclass, pmode, payer) VALUES ('$tdate', '$payeename','$tamount', '$tclass','$keyb','$payeename')");
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}elseif ($keyb=="2" && $keyc =="1"){
$result = mysqli_query($mysqli, "INSERT INTO cashbook(tdate, chequeno, originator, cr_amount, tclass, pmode, payer) VALUES('$tdate', '$chequeno','$suppliername','$tamount','$tclass','$keyb','$payeename')");
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}elseif ($keyb=="2" && $keyc =="2") {
$result = mysqli_query($mysqli, "INSERT INTO cashbook(tdate, chequeno, originator, cr_amount, tclass, pmode, payer) VALUES('$tdate','$chequeno', '$payeename','$tamount', '$tclass','$keyb','$payeename')");
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}elseif ($keyb=="1" && $keyc =="1") {
$result = mysqli_query($mysqli, "INSERT INTO cashbook(tdate, originator, cr_amount, tclass, pmode, payer) VALUES('$tdate','$suppliername','$tamount','$tclass','$keyb','$payeename')");
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}else {
echo "error,,";
}
?>
</body>
</html>
My problem is that, the only time data gets inserted is when $keyb=='2' and $keyc=='2'(this is one of the conditions). However, for the other 3 conditions, nothing gets inserted even in instances when those conditions are met.
Kindly help me out.
</div>