/    Sign up×
Community /Pin to ProfileBookmark

Why is this not writing to the database?

Hello,

I cant seem to figure out why this code is not writing to the database? It is a file that is included in another file that already has a connection to the database established. It does not seem like it is running at all but there are no errors being returned. It is suppose to be generating a download key and inserting it into the database then sending an email with the download link provided in it. Can anyone help me figure out why its not inserting anything into the database or sending out emails? Here is the code:

[code=php]
<?php

$keys = htmlspecialchars($numbkey1, ENT_QUOTES);
$successkeys = 0;
?>

<?php 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(‘U’);

for ($counter = 1; $counter <= $keys; $counter += 1) {
// Generate the unique download key
$key = substr(uniqid(md5(rand())), 0, 12);

// Generate the link
$link=$folderpath . “download.php?id=” . $key . “<br />n”;

// Sanitize the query
$query = “INSERT INTO downloadkeys (uniqueid,timestamp,lifetime,maxdownloads,downloads,filename) VALUES(“$key”,”$time”,’&#37;d’,’%d’,’%d’,’%s’)”,
$lifetime,
$maxdownloads,
0,
mysqli_real_escape_string($filename, $dbc),

// Write the key and other information to the DB as a new row
$registerid = mysqli_query($query) or die(mysqli_error());

$successkeys++;
}

}
if ( isset($_POST[‘payment_status’])
&& ($_POST[‘payment_status’] == ‘Completed’)
&& ($_POST[‘receiver_email’] == ‘[email protected]’)
&& ($_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’] == ‘[email protected]’)
&& ($_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!’);
}

}
}
}
}

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: [email protected]’);
}
[/code]

Thanks in advance if you can help me figure this out.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ZABIMar 05.2012 — try using error_reporting(E_ALL); at the top of your file. so you may see the error message and line number etc...
Copy linkTweet thisAlerts:
@DasherMar 05.2012 — Your $query is not terminated with a ; and the $time portion of the insert does not have proper use of ().
Copy linkTweet thisAlerts:
@mccoauthorMar 06.2012 — Hey guys I made changes but with no difference. I still cant figure out why it is not writing anything to the database. Here is my adjusted code, please if anyone can help me figure this out. It is driving me insane. Since it is part of my ipn code it doesnt show any errors on screen and the error log on my server that I had been using to find errors in the script is not showing any errors.

[code=php]

<?php

if ( isset($_POST['payment_status'])
&& ($_POST['payment_status'] == 'Completed')
&& ($_POST['receiver_email'] == '[email protected]')
&& ($_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'] == '[email protected]')
&& ($_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);

// Generate the link
$link=$folderpath . "thanks.php?id=" . $key . "<br />n";

// Sanitize the query
$query = "INSERT INTO downloadkeys (uniqueid,timestamp,lifetime,maxdownloads,downloads,filename) VALUES('$key','$time','31556926','2','%d','$filename')";
mysqli_real_escape_string($filename);

// Write the key and other information to the DB as a new row
$registerid = mysqli_query($dbc,$query);
if (mysqli_affected_rows($dbc) != 1) {
trigger_error('The user's expiration date could not be updated!');
}
$successkeys++;
}

}


}
}
}
}

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: [email protected]');
}

[/code]


It is bugging me because this is the last part of my site that I have to finish to get it up and running so please if anyone can think of anything I could try it would be very welcome.
Copy linkTweet thisAlerts:
@DasherMar 06.2012 — I would echo your query to make sure it contains the data you think it should. Is &#37;d data? It is being used as data... is it the correct data type... should it be $d ? Maxdownloads sounds like it should be an integer, but %d is a string.

Is $dbc set to the correct link, is the correct database selected?
×

Success!

Help @mcco spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...