...

View Full Version : Using PHP to Record payments into database



mbarandao
12-07-2010, 04:16 AM
Hello:

Here is an interesting question.

I have a client payment recording form which retrieves data from a table that has clients balances and other.

My task with this form is to take payments (which can be payments in full or partial payments). I need to be able to update the originating table with new payments as well as have the ability to record multiple payment to this account.

Not sure if this is doable with the existing table or will I need a separate table in conjunction with the initial table.

Currently I'm able to update the originating table in this way:



<?php
error_reporting(0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//error_reporting(E_ALL);

$host = "localhost";
$login_name = "23232";
$password = "23232242";

$link=mysql_connect("$host","$login_name","$password");
mysql_select_db("shop", $link);
//or die("Could not find database");
//echo mysql_errno() . ": " . mysql_error(). "\n";

// define each variable
if(isset($_POST['submit']))//this defines any variable that are not define below
{
$edit_sel_id = mysql_real_escape_string($_POST['edit_sel_id']);
$paymentamount = $_POST['paymentamount'];
$paymenttype = mysql_real_escape_string($_POST['paymenttype']);
$paymentref = mysql_real_escape_string($_POST['paymentref']);
$paymentdate = mysql_real_escape_string($_POST['paymentdate']);
$memo = mysql_real_escape_string($_POST['memo']);
$newbalance=$_POST['newbalance'];
$newbalance= "$".''.$newbalance;
$paymentamount= "$".''.$paymentamount;

if ($edit_sel_id == "") echo "! No identifier retrieved";
else

$mysql_query=("UPDATE billofservice SET newpayment_date=NOW(), newpayment_amount='$paymentamount', newpayment_type='$paymenttype',
paymentref='$paymentref', newpmtmemo='$memo', Balancedue='$newbalance' WHERE id=$edit_sel_id");
$result=mysql_query($mysql_query);
if(!$result){die("Error: ".mysql_error());
}
mysql_close($link);
}

?>


I need to figure out a plan when partial payments needs to be entered --as this current mechanism would replace exiting fields with new ones.
Any thoughts!
Mossa

Fumigator
12-07-2010, 05:02 PM
You should definitely have a table to store all payments that come in, separate from what the payment gets applied to. Applying payments to invoices should be handled with yet another table that relates payment to invoice. But all this really depends on what system of accounting you're using-- balance forward? open item? What?

mbarandao
12-08-2010, 03:27 AM
Issue resolved!
Thanks for all the suggestions...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum