Hi,
I have written php program, which is used for user paid subscription. I am not a programmer, i learnt PHP and was able to write this code (i copied credit card function from internet). Everything works fine, except after confirmation if i click browser refresh button, script tries update database again with same values and database wont allow due to unique key constraint. I think using PHP session would resolve the issue. However i am confused with PHP sessions. Can someone help me to integrate PHP sessions within this program.
<?php
//Begin get credit card types from DB....
function get_cc_type_db (&$CC_Type, &$CC_Type_CD){
include('modules/configora.php');
get credit card_type bfrom DB....
}
//End get credit card types from DB....
//Begin User_login exists check DB....
function user_login_check_db($user_login, &$USER_EXISTS){
include('modules/configora.php');
....database update.....
//End Subscription Update DB....
//Begin FORM.....
function user_reg_form(&$user_reg_info, &$error_reg_array){
FORM.....
}
//END FORM.......
//Begin Subscription Confirmation.,....
function user_subscription_confirm(&$user_reg_info){
subscription confirmation......
}
//END Subscription confirmation....
//Begin Credit Card validation...
function checkCreditCard ($cardnumber, $cardname, &$errornumber, &$errortext) {
credit card validity check.......
return true;
}
//END Credit card validation....
//Begin Form validation....
function user_reg_check(&$user_reg_info, &$error_reg_array) {
form error check.....
return user_reg_check;
}
//END From validation......
//MAIN.....
if(isset($_POST['register'])){
$_SESSION['user_login'] = $_POST['user_login'];
$error_reg_array = array();
$user_reg_info = array();
$user_reg_info = $_POST;
user_reg_check($user_reg_info, $error_reg_array);
$cnt = count($error_reg_array);
if($cnt > 0){
user_reg_form($user_reg_info, $error_reg_array);
}else{
$user_reg_info = $_POST;
user_subscription_confirm($user_reg_info);
}
}else{
if(isset($_POST['edit'])){
$error_reg_array = array();
$user_reg_info = $_POST;
user_reg_form($user_reg_info, $error_reg_array);
}else{
if(isset($_POST['confirm'])){
$user_reg_info = $_POST;
$user_reg_info[user_login] = strtoupper($user_reg_info[user_login]);
subscription_update($user_reg_info);
}else{
if(isset($_POST['cancel'])){
header("Location: acctmgnt.html");
}else{
$error_reg_array = array();
$user_reg_info = array ( 'first_name' => '',
'last_name' => '',
'phone_no' => '',
'fax_no' => '',
'email_address' => '',
'business_name' => '',
'street_name1' => '',
'street_name2' => '',
'city' => '',
'state' => '',
'postal_code1' => '',
'postal_code2' => '',
'province' => '',
'country' => '',
'foreign_postal_code' => '',
'payment_acct_type' => '',
'payment_acct_num' => '',
'month' => '',
'year' => '',
'payment_acct_name' => '',
'user_login' => '',
'passwd1' => '',
'passwd2' => '',
'user_id' => '' );
$user_reg_info[user_login] = strtoupper($user_reg_info[user_login]);
user_reg_form($user_reg_info, $error_reg_array);
}
}
}
}
?>
</BODY>
</HTML>
I have removed some of the PHP codes within function to make this program smaller (1250 lines code) and easier to understand and to upload to PHPBUILDER.com.
Thanks,
PHSSSH