Hi,
I am new to PHP. I am facing a problem while adding data to the MySql Database . I have 2 forms .I have inserted some data to the databse but but after getting the data from form i have to calculate the data , but when i am trying to insert data to the database then the data is not inserted to the database. Please help me.
bimal_nayak 0 Newbie Poster
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
<?php
//Session Start
session_start();
//Database Connectivity
require_once ("dbconnect.php");
//Retriving User Details from the Database
$user_id=$_SESSION['session_user_id'];
$query1="SELECT * FROM sm_users WHERE user_id='$user_id'";
$result1=mysql_query($query1);
$row1=mysql_fetch_array($result1);
$user_name=$row1['user_name'];
//Checking the genuine session
if(isset($_SESSION['session_user_id']))
{
?>
<?php
$action=$_REQUEST['action'];
if($action=="insert")
{
$application_no=$_POST['application_no'];
$branch_code=$_POST['branch_code'];
$branch_name=$_POST['branch_name'];
$customer_name=$_POST['customer_name'];
$guardian_name=$_POST['guardian_name'];
$spouse_name=$_POST['spouse_name'];
$DOB=$_POST['DOB'];
$cur_address=$_POST['cur_address'];
$per_address=$_POST['per_address'];
$contact_no=$_POST['contact_no'];
$email_id=$_POST['email_id'];
$gender=$_POST['gender'];
$marital_status=$_POST['marital_status'];
$verification_detail=$_POST['verification_detail'];
$agent_code=$_POST['agent_code'];
$agent_name=$_POST['agent_name'];
$plan_opted=$_POST['plan_opted'];
$amount_invested=$_POST['amount_invested'];
$payment_frequency=$_POST['payment_frequency'];
$payment_mode=$_POST['payment_mode'];
$date_commencement=$_POST['date_commencement'];
$maturity_amount=$_POST['maturity_amount'];
$maturity_date=$_POST['maturity_date'];
$nominee_name=$_POST['nominee_name'];
$relation_applicant=$_POST['relation_applicant'];
$nominee_age=$_POST['nominee_age'];
$nominee_cu_address=$_POST['nominee_cu_address'];
$nominee_per_address=$_POST['nominee_per_address'];
$date_commencement=$_POST['date_commencement'];
$query4="INSERT INTO titan_customer SET " ;
$query4.="application_no='$application_no',";
$query4.="branch_code='$branch_code',";
$query4.="branch_name='$branch_name',";
$query4.="customer_name='$customer_name',";
$query4.="guardian_name='$guardian_name',";
$query4.="spouse_name='$spouse_name',";
$query4.="DOB='$DOB',";
$query4.="cur_address='$cur_address',";
$query4.="per_address='$per_address',";
$query4.="contact_no='$contact_no',";
$query4.="email_id='$email_id',";
$query4.="gender='$gender',";
$query4.="marital_status='$marital_status',";
$query4.="verification_detail='$verification_detail',";
$query4.="agent_code='$agent_code',";
$query4.="agent_name='$agent_name',";
$query4.="plan_opted='$plan_opted',";
$query4.="amount_invested='$amount_invested',";
$query4.="payment_frequency='$payment_frequency',";
$query4.="payment_mode='$payment_mode',";
$query4.="date_commencement=now(),";
$query4.="maturity_amount='$maturity_amount',";
$query4.="maturity_date='$maturity_date',";
$query4.="nominee_name='$nominee_name',";
$query4.="relation_applicant='$relation_applicant',";
$query4.="nominee_age='$nominee_age',";
$query4.="nominee_cu_address='$nominee_cu_address',";
$query4.="nominee_per_address='$nominee_per_address'";
$result4=mysql_query($query4);
$customer_id=mysql_insert_id();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Branch Master Maintenence</title>
<script language="javascript" src="<?php echo $URL;?>calander/calendar.js"></script>
<script language="javascript" src="<?php echo $URL;?>calander/calendar-en.js"></script>
<script language="javascript" src="<?php echo $URL;?>calander/calendar-setup.js"></script>
<link rel="stylesheet" href="<?php echo $URL;?>calander/calendar-win2k-cold-1.css">
<!-- Calander -->
<script language="javascript" type="text/javascript">
function checknull()
{
if(document.customer_details.application_no.value=="") // Application No.
{
alert('Please Enter Application No.');
document.customer_details.application_no.focus();
return false;
}
if(document.customer_details.branch_code.value==0) // Branch Code
{
alert('Please Enter New Branch Code of the customer and agent belongs to');
document.customer_details.branch_code.focus();
return false;
}
if(document.customer_details.branch_name.value==0) // Branch name
{
alert('Please Enter New Branch Name of the customer and agent belongs to');
document.customer_details.branch_name.focus();
return false;
}
if(document.customer_details.customer_name.value=="") // Customer name
{
alert('Please Enter New Customer Name');
document.customer_details.customer_name.focus();
return false;
}
if(document.customer_details.guardian_name.value==0) // Customer's father/ Husband Name
{
alert('Please Enter the Customer \'s Father \'s Name or Husband \'s Name ');
document.customer_details.guardian_name.focus();
return false;
}
if(document.customer_details.DOB.value==0)//Customer's DOB
{
alert('Please Enter a Valid date Of Birth.');
document.customer_details.DOB.focus();
return false;
}
if(document.customer_details.cur_address.value=="")//Customer's Current Address
{
alert('Please Enter the Current address of the Customer.');
document.customer_details.cur_address.focus();
return false;
}
if(document.customer_details.per_address.value=="")//Customer's Permanent Address
{
alert('Please Enter the Permanent address of the Customer.');
document.customer_details.per_address.focus();
return false;
}
if(document.customer_details.contact_no.value=="")//Contact No.
{
alert('Please Enter the Contact No.');
document.customer_details.contact_no.focus();
return false;
}
if (isNaN(document.customer_details.contact_no.value))
{
alert('Please enter Contact No. in numbers only');
document.customer_details.contact_no.focus();
return false;
}
if(document.customer_details.email_id.value=="")// Agent's email ID
{
alert('Please Enter E-Mail Address ');
document.customer_details.email_id.focus();
return false;
}
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
//check for valid email
if(emailPattern.test(document.customer_details.email_id.value)== false)
{
alert('E-Mail Address is not valid');
document.customer_details.email_id.focus();
return false;
}
myOption = -1;
for (i=document.customer_details.gender.length-1; i > -1; i--) { // Radio Button for gender
if (document.customer_details.gender[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select The gender");
return false;
}
myOption = -1;
for (i=document.customer_details.marital_status.length-1; i > -1; i--) { // Radio Button for Marital Status
if (document.customer_details.marital_status[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select The Marital Status");
return false;
}
if(document.customer_details.verification_detail.value=="")//Verification Details
{
alert('Please Enter a Valid Verification Detail.');
document.customer_details.verification_detail.focus();
return false;
}
if(document.customer_details.agent_code.value=="")//Agent's Code
{
alert('Please Enter Agent Code of the Respective Customer.');
document.customer_details.agent_code.focus();
return false;
}
if(document.customer_details.agent_name.value==0)//Agent's Name
{
alert('Please Enter a Name of the Respective Agent.');
document.customer_details.agent_name.focus();
return false;
}
if(document.customer_details.plan_opted.value==0)//Plan Details
{
alert('Please Enter a Plan details of the Customer.');
document.customer_details.plan_opted.focus();
return false;
}
if(document.customer_details.amount_invested.value==0)// Details of Amount Invested
{
alert('Please Enter a valid amount invested by the Customer,that should be dinomination of Rs. 100/-.');
document.customer_details.amount_invested.focus();
return false;
}
if (isNaN(document.customer_details.amount_invested.value))// Details of Amount Invested
{
alert('Please enter Amount in only numbers');
document.customer_details.amount_invested.focus();
return false;
}
if(document.customer_details.payment_frequency.value==0)//Payment Frequency
{
alert('Please Enter Frequency of the Payment.');
document.customer_details.payment_frequency.focus();
return false;
}
if(document.customer_details.payment_mode.value==0)//Payment Mode
{
alert('Please Enter Mode of Payment.');
document.customer_details.payment_mode.focus();
return false;
}
if(document.customer_details.nominee_name.value=="")//Nominee Name
{
alert('Please Enter Nominee Name of the Respective Customer.');
document.customer_details.nominee_name.focus();
return false;
}
if(document.customer_details.relation_applicant.value=="")//Nominee with Relation applicant
{
alert('Please Enter Relation with Nominee of the Respective Customer.');
document.customer_details.relation_applicant.focus();
return false;
}
if(document.customer_details.nominee_age.value=="")//Age of Nominee
{
alert('Please Enter Age of Nominee of the Respective Customer.');
document.customer_details.nominee_age.focus();
return false;
}
if (isNaN(document.customer_details.nominee_age.value))//Age of Nominee
{
alert('Please enter age in only numbers');
document.customer_details.nominee_age.focus();
return false;
}
if(document.customer_details.nominee_cu_address.value=="")//Current Address of Nominee
{
alert('Please Enter Current Address of Nominee of the Respective Customer.');
document.customer_details.nominee_cu_address.focus();
return false;
}
if(document.customer_details.nominee_per_address.value=="")//Permanent Address of Nominee
{
alert('Please Enter Permanent Address of Nominee of the Respective Customer.');
document.customer_details.nominee_per_address.focus();
return false;
}
}
</script>
<style type="text/css">
<!--
.st
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
<?php
//Session Start
session_start();
//Database Connectivity
require_once ("dbconnect.php");
//Retriving User Details from the Database
$user_id=$_SESSION['session_user_id'];
$query1="SELECT * FROM sm_users WHERE user_id='$user_id'";
$result1=mysql_query($query1);
$row1=mysql_fetch_array($result1);
$user_name=$row1['user_name'];
//Checking the genuine session
if(isset($_SESSION['session_user_id']))
{
$action=$_REQUEST['action'];
if($action=="insert")
{
$application_no=$_POST['application_no'];
$branch_code=$_POST['branch_code'];
$branch_name=$_POST['branch_name'];
$customer_name=$_POST['customer_name'];
$guardian_name=$_POST['guardian_name'];
$spouse_name=$_POST['spouse_name'];
$DOB=$_POST['DOB'];
$cur_address=$_POST['cur_address'];
$per_address=$_POST['per_address'];
$contact_no=$_POST['contact_no'];
$email_id=$_POST['email_id'];
$gender=$_POST['gender'];
$marital_status=$_POST['marital_status'];
$verification_detail=$_POST['verification_detail'];
$agent_code=$_POST['agent_code'];
$agent_name=$_POST['agent_name'];
$plan_opted=$_POST['plan_opted'];
$amount_invested=$_POST['amount_invested'];
$payment_frequency=$_POST['payment_frequency'];
$no_of_instalment=$_GET['no_of_instalment'];
$payment_mode=$_POST['payment_mode'];
$date_commencement=$_POST['date_commencement'];
$maturity_amount=$_POST['maturity_amount'];
$maturity_date=$_POST['maturity_date'];
$nominee_name=$_POST['nominee_name'];
$relation_applicant=$_POST['relation_applicant'];
$nominee_age=$_POST['nominee_age'];
$nominee_cu_address=$_POST['nominee_cu_address'];
$nominee_per_address=$_POST['nominee_per_address'];
$date_commencement=$_POST['date_commencement'];
$query4="INSERT INTO titan_customer SET " ;
$query4.="application_no='$application_no',";
$query4.="branch_code='$branch_code',";
$query4.="branch_name='$branch_name',";
$query4.="customer_name='$customer_name',";
$query4.="guardian_name='$guardian_name',";
$query4.="spouse_name='$spouse_name',";
$query4.="DOB='$DOB',";
$query4.="cur_address='$cur_address',";
$query4.="per_address='$per_address',";
$query4.="contact_no='$contact_no',";
$query4.="email_id='$email_id',";
$query4.="gender='$gender',";
$query4.="marital_status='$marital_status',";
$query4.="verification_detail='$verification_detail',";
$query4.="agent_code='$agent_code',";
$query4.="agent_name='$agent_name',";
$query4.="plan_opted='$plan_opted',";
$query4.="amount_invested='$amount_invested',";
$query4.="amount_invested_total='amount_invested_total',";
$query4.="payment_frequency='$payment_frequency',";
$query4.="payment_mode='$payment_mode',";
$query4.="date_commencement=now(),";
$query4.="total_maturity_amount='$total_maturity_amount',";
$query4.="maturity_date='$maturity_date',";
$query4.="nominee_name='$nominee_name',";
$query4.="relation_applicant='$relation_applicant',";
$query4.="nominee_age='$nominee_age',";
$query4.="nominee_cu_address='$nominee_cu_address',";
$query4.="nominee_per_address='$nominee_per_address'";
$result4=mysql_query($query4);
$customer_id=mysql_insert_id();
//DATA CALULATION AND INSERT START
//Step 1 : Get Plan selected and Amount Invested and commencement date (We already have this)
//Plan Selected in : $plan_opted
//Amount Invested in : $amount_invested
//Commencement date in : $today_date
$data = mktime(date("H")+5, date("i")+30, date("s"), date("m"), date("d"), date("Y"), date("O"));
$today_date=date("Y-m-d", $data);
//Step 2 : Calculate maturity amount and maturity date
$query51="SELECT * FROM plan WHERE plan_name='$plan_opted'"; // taking the data for plan selected, from database
$result51=mysql_query($query51);
$row51=mysql_fetch_array($result51);
$months=$row51['months'];
$rate_interest=$row51['rate_interest'];
//Calculating no. of instalment
if($payment_frequency=="Monthly")
{
$no_of_instalment=$months/1;
}
elseif($payment_frequency=="Quarterly")
{
$no_of_instalment=$months/3;
}
elseif($payment_frequency=="Halfyearly")
{
$no_of_instalment=$months/6;
}
elseif($payment_frequency=="Yearly")
{
$no_of_instalment=$months/12;
}
else
{
$no_of_instalment=1;
}
//Total Amount Invested
$amount_invested_total=$amount_invested*($row51['months']);
//Maturity Amount
$maturity_amount=(($amount_invested_total)*($row51['months']/12)*($row51['rate_interest'])/100);
$total_maturity_amount=($amount_invested_total) + ($maturity_amount);
//Maturity Date
$maturity_date_data = mktime(date("H")+5, date("i")+30, date("s"), date("m")+18, date("d"), date("Y"), date("O"));
$maturity_date=date("Y-m-d", $maturity_date_data);
//Step 3 : enter the Maturity amount and maturity date in database
$querye="UPDATE titan_customer SET maturity_amount='$maturity_amount',maturity_date='$maturity_date',plan_noof_installment='$no_of_instalment' WHERE customer_id='$customer_id'";
$resulte=mysql_query($querye);
echo "Maturity Amount : ".$maturity_amount."<br />";
echo "Maturity Date : ".$maturity_date."<br />";
//DATA CALULATION AND INSERT ENDS
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Branch Master Maintenence</title>
<style type="text/css">
<!--
.style2 {
font-size: 24px;
font-weight: bold;
text-decoration:underline;
}
.style3{ font-size:18px;
font-weight:bold;
text-decoration:underline;
}
.style4{ font-size:14px;
font-weight:bold;
text-decoration:none;
color:#FF0000;
}
.style7 {color: #FFFFFF}
.style13 {color: #999999; font-weight: bold; }
-->
</style>
</head>
<body>
<table width="999" height="1163" border="0">
<tr>
<td height="21" colspan="3"><?php require_once('date&logo.php'); ?></td>
</tr>
<tr>
<td height="28" colspan="3" align="left"><strong>Welcome <?php echo $user_name; ?></strong></td>
</tr>
<tr>
<td colspan="3" bgcolor="#000000" height="3"></td>
</tr>
<tr>
<td width="67" height="55"> </td>
<td width="853" align="left" valign="middle"><span class="style2">Details of Customer </span></td>
<td width="60"> </td>
</tr>
<tr>
<td height="1009"> </td>
<td align="left" valign="top"><br /><div align="center"><span class="style4">Customer has been listed Successfully</span></div><br />
<table width="865" border="0" >
<td width="31" height="35"> </td>
<td width="286" align="right" valign="middle"><span class="style13">Application No.:</span></td>
<td colspan="2"><span class="style7"><?php echo $application_no; ?></span></td>
</tr>
<tr>
<td width="31" height="35"> </td>
<td width="286" align="right" valign="middle"><span class="style13">Branch Code:</span></td>
<td colspan="2"><span class="style7"><?php echo $branch_code; ?></span></td>
</tr>
<tr>
<td width="31" height="35"> </td>
<td width="286" align="right" valign="middle"><span class="style13">Branch Name:</span></td>
<td colspan="2"><span class="style7"><?php echo $branch_name; ?></span></td>
</tr>
<tr>
<td width="31" height="35"> </td>
<td width="286" align="right" valign="middle"><span class="style13">Customer ID:</span></td>
<td colspan="2"><span class="style7"><?php echo $customer_id; ?></span></td>
</tr>
<tr>
<td width="31" height="35"> </td>
<td width="286" align="right" valign="middle"><span class="style13">Name:</span></td>
<td colspan="2"><span class="style7"><?php echo $customer_name; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Father's Name / Husband Name: </span></td>
<td colspan="2"><span class="style7"><?php echo $guardian_name; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Date of Birth. </span></td>
<td colspan="2"><span class="style7"><?php echo $DOB; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13"> Current Address:</span></td>
<td colspan="2"><span class="style7"><?php echo $cur_address; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13"> Permanent Address:</span></td>
<td colspan="2"><span class="style7"><?php echo $per_address; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Contact No: </span></td>
<td colspan="2"><span class="style7"><?php echo $contact_no;?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Mail ID : </span></td>
<td colspan="2"><span class="style7"><?php echo $email_id;?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Gender: </span></td>
<td colspan="2"><span class="style7"><?php echo $gender; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Marital Status: </span></td>
<td colspan="2"><span class="style7"><?php echo $marital_status; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Verification Details : </span></td>
<td colspan="2"><span class="style7"><?php echo $verification_detail; ?></span></td>
</tr>
<tr>
<td height="35"> </td>
<td align="right" valign="middle"><span class="style13">Agent Code: </span></td>
<td colspan="2"><span clas
rajarajan2017
What is the error shown when executing? which file?
bimal_nayak 0 Newbie Poster
First I am adding data to the add_customer_details.php file, then i am adding data to the database & catching the data in the customer_details.php file & doing the calculation and again adding the data to the database. but while adding the data to the database for 2nd time the data is not added to the database. Please help me
vaultdweller123 32 Posting Pro
whooaaaaa! thats a lot of code! my braincells are depleted!
bigjoke 0 Light Poster
yea.. im not going through that many lines of code mate....
tell us where the problem exactly is, and what is the error you are coming across...
Make sure to remember that the data AFTER calculation is still the same format that the database expects. e.g. int is still an int after calculation is finished.
regards
bimal_nayak 0 Newbie Poster
hi....
Exactly the problem is that i am adding data to to the database through a form field. then i am catching those data and doing some necessary calculations. After that i am trying to update the database through the calculated data. When i am trying to add those calculated data then the problem arise & i cant add store the data inside database. Please help me.....
Zagga
Hi bimal nayak,
As people have suggested, you need to tell us what error message is being displayed.
You have 999 lines of code. You need to make your haystack a little smaller before we can help you find the needle.
Zagga
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.