I am having an issue with my code that I cant seem to get figured out. This code is a file that is included in my ipn.php file that is suppose to be generating a unique download key once the purchase has been confirmed. There is already a connection to the DB earlier in the script. I know that my DB connections are correct as the orders and users are inserted into the tables just fine. I cant seem to figure out why this part of the script would not write to the db. Here is my code:
- Code: Select all
<?php
if ( isset($_POST['payment_status'])
&& ($_POST['payment_status'] == 'Completed')
&& ($_POST['receiver_email'] == 'mccoym_1330569552_biz@sportdirections.com')
&& ($_POST['mc_gross'] == 9.99)
&& ($_POST['mc_currency'] == 'USD')
&& (!empty($_POST['txn_id']))
) {
$numbkey1 = 1;
$filename = 'cover01.zip';
$lifetime = 31556926;
$maxdownloads = 2;
} elseif {
( isset($_POST['payment_status'])
&& ($_POST['payment_status'] == 'Completed')
&& ($_POST['receiver_email'] == 'mccoym_1330569552_biz@sportdirections.com')
&& ($_POST['mc_gross'] == 14.99)
&& ($_POST['mc_currency'] == 'USD')
&& (!empty($_POST['txn_id']))
) {
$numbkey1 = 1;
$filename = 'cover02.zip';
$lifetime = 31556926;
$maxdownloads = 2;
} else { // Problem finding the order!
trigger_error('The transaction could not be found in the table!');
}
}
$keys = htmlspecialchars($numbkey1, ENT_QUOTES);
$successkeys = 0;
if(is_numeric($keys) && $filename != "") {
// A script to generate unique download keys for the purpose of protecting downloadable goods
if(empty($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
}
// Strip off query string so dirname() doesn't get confused
$url = preg_replace('/\?.*$/', '', $_SERVER['REQUEST_URI']);
$folderpath = 'http://'.$_SERVER['HTTP_HOST'].'/'.ltrim(dirname($url), '/').'/';
// Get the activation time
$time = date();
for ($counter = 1; $counter <= $keys; $counter += 1) {
// Generate the unique download key
$key = substr(uniqid(md5(rand())), 0, 12);
// Write the key and other information to the DB as a new row
$query = "INSERT INTO downloadkeys (uniqueid,timestamp,lifetime,maxdownloads,filename) VALUES ('$key','$time','31556926','2','$filename')";
$registerid = mysqli_query($dbc,$query);
if (mysqli_affected_rows($dbc) != 1) {
trigger_error('The user\'s expiration date could not be updated!');
}
$successkeys++;
}
// Generate the link
$link=$folderpath . "thanks.php?id=" . $key . "<br />\n";
}
}
}
}
}
if($successkeys > 0) {
$body = "Thank you for purchasing our E-Book. Here is your custom download link:" $link.;
mail($_POST['email'], 'Strategies for Stretching Your Income Delivery', $body, 'From: orders@stretchmyincome.com');
}
Any help anyone can give me would be great as this is the last part of my website that I need to figure out before it goes live. Thanks in advance.

