A
Anonymous
Guest
Hello to all developers here and please excuse me if I do something wrong in asking a question as I am a first-comer to this great forum.
I am trying to store a row value from one table into another without success.
Please find the code example below with explanation.
This is part of the index.php where the value from $userID is stored in $custom variable. The 'firstname' row is found in the 'members' table.
This is a part of the ipn.php where the information is stored into database after successful transaction. The problem is it does not store value from $custom variable into subscr_id row found in members table:
What am I doing wrong here, can someone show me on how to solve this problem?
P.S. I have tried to store a row containing number or email in a session variable before, but can't login and always returns me to the login page.
Thank you,
Emma
I am trying to store a row value from one table into another without success.
Please find the code example below with explanation.
This is part of the index.php where the value from $userID is stored in $custom variable. The 'firstname' row is found in the 'members' table.
Code:
<?php
// code in between excluded for clarity
$userID = !empty($_SESSION['firstname'])?$_SESSION['firstname']:header("Location: {$home_url}login.php?action=please_login");
?>
<form action="<?php echo PAYPAL_URL; ?>" method="post">
<input type="hidden" name="custom" value="<?php echo $userID; ?>">
</form>
This is a part of the ipn.php where the information is stored into database after successful transaction. The problem is it does not store value from $custom variable into subscr_id row found in members table:
Code:
if (strcmp($res, "VERIFIED") == 0 || strcasecmp($res, "VERIFIED") == 0) {
//... code in between excluded for clarity
// Retrieve transaction data from PayPal
$txn_id = !empty($_POST['txn_id'])?$_POST['txn_id']:'';
$custom = $_POST['custom'];
//... code in between excluded for clarity
if(!empty($txn_id)){
// Check if transaction data exists with the same TXN ID
$prPayment = $db->query("SELECT id FROM user_subscr WHERE txn_id = '".$txn_id."'");
if($prPayment->num_rows > 0){
exit();
}else{
// Insert transaction data into the database
$insert = $db->query("INSERT INTO user_subscr(user_id,txn_id) VALUES('".$custom."','".$txn_id."')");
// Update subscription id in the members table
if($insert && !empty($custom)){
// 'firstname' is stored in $subscr_id
$subscr_id = $custom;
// does not update value from 'user_id' row found in 'user_subscr' table into 'subscr_id' row found in 'members' table. The 'subscr_id' row is always empty.
$update = $db->query("UPDATE members SET subscr_id = {$subscr_id} WHERE firstname = {$custom}");
}
}
}
}
die;
P.S. I have tried to store a row containing number or email in a session variable before, but can't login and always returns me to the login page.
Thank you,
Emma