Change Value in Database after form submit

darrenhallinan 03 Oct, 2011
Hi All

I am using CF as part of a payment processor,

if payment is ok the payment gateway will send user to:
index.php?option=com_chronocontact&chronoformname=payment_ok

and if declined or cancelled the payment gateway goes to:
index.php?option=com_chronocontact&chronoformname=payment_canceled

in the database table i have a row called paid and the default value is 0

I want to change this value to 1 if the payment is paid

anyone have any ideas on how I can do this?
darrenhallinan 03 Oct, 2011
I thought id expand on what i am doing here. . .

I use a form to fill in details of a payment request

feilds include

firstname
lastname
pay_from_email
amount
discription_text
paid

when submitted the forms sends a payment request to the person

the data is saved in a table

in the email the persons receives there is a link to another form:
index.php?option=com_chronocontact&chronoformname=make_payment&uid={uid}


Using the profile page plugin to connect to the table
this populates the form of the payment gateway with the required details
and the person clicks the link to go to the payment gateway and pay.

within the form on this page are to values
<input type="hidden" name="return_url" value="http://www.domainname.com/index.php?option=com_chronocontact&chronoformname=payment_ok&uid={uid}">
<input type="hidden" name="cancel_url" value="http://www.domainname.com/index.php?option=com_chronocontact&chronoformname=payment_canceled&uid={uid}">


these values say where to send the user after payment has been accepted or declined

these two forms are also using the profile page plugin which pulls the details from the table
<center><img src="images/loading.gif" align="center" width="424" height="424" style="border-color: initial; display: block; padding: 0px; margin: 0px;" /><br><h2>Your payment details are been processed please wait. . .</h2></center>
<div class="form_item">
<div class="form_element cf_button">
<input value="Click Here If Not Redirected" name="button_4" type="submit" />
</div>
<div class="cfclear"> </div>
</div>

<input value="{firstname}" id="hidden_0" name="firstname" type="hidden" />

<input value="{lastname}" id="hidden_1" name="lastname" type="hidden" />

<input value="{amount}" id="hidden_2" name="amount" type="hidden" />

<input value="{pay_from_email}" id="hidden_3" name="pay_from_email" type="hidden" />
<script language="JavaScript">
<!--
window.setTimeout(GoPayment,4000);
function GoPayment(){
document.ChronoContact_payment_ok.submit();
}
-->
</script>


the above code is the payment ok form where the user is redirected to when payment is ok.

using JS the form submits on it own after 4 seconds and the user sees the "On Submit code - after sending email"

and the form sends confirmation to both myself and the user that's the payment has gone through ok

but I want to change the "paid" value in the table at this stage from "0" to "1"

I'm sure is just a matter of putting code in the "On Submit code - after sending email" but what would that code be?
darrenhallinan 03 Oct, 2011
I am guessing its something like this
<?php
$db =& JFactory::getDBO();
$query = "
UPDATE SET paid = '1'
FROM `#__chronoforms_payment_request`
WHERE uid = '$uid' ";
?>


if anyone can help me here,the above code does not work but it cant be to far off can it?
GreyHead 04 Oct, 2011
hi darrenhallinan,

If in doubt about your MySQL it's worth checking the manual for the syntax and/or testing in PHPMyAdmin to see what errors show up. Please try
<?php
$db =& JFactory::getDBO();
$query = "
  UPDATE `#__chronoforms_payment_request`
    SET `paid` = '1'
    WHERE `uid` = '$uid' ;
";
$db->setQuery($query);
$db->query();
?>

Bob
This topic is locked and no more replies can be posted.