I’m building a custom IPN handler in PHP, which validates the data Paypal sends in a postback, and then inserts some of it into an sqlite database.
Every part of the script has worked before.
Transactions get reported as valid, and logged. Everything works, up to line 32, which calls a custom function.
Here’s line 32:
$sql = insert_query_builder("PP_Data", $keywords);
and here’s how the function’s defined, in a require()‘d file:
function insert_query_builder($table, $keywords, $info = NULL) {
$sql_1 = "INSERT INTO $table (";
$sql_2 = ") VALUES (";
foreach ( $keywords as $num => $keyword ) {
if (isset($info)) {
if ($num != (count($keywords - 1))) {
$sql_2 .= $db->quote($info[$keyword]) . ", ";
$sql_1 .= $keyword . ", ";
} else {
$sql_2 .= $db->quote($info[$keyword]) . ")";
$sql_1 .= $keyword;
}
} else {
if ($num != (count($keywords - 1))) {
$sql_2 .= $db->quote($_POST[$keyword]) . ", ";
$sql_1 .= $keyword . ", ";
} else {
$sql_2 .= $db->quote($_POST[$keyword]) . ")";
$sql_1 .= $keyword;
}
}
}
$sql = $sql_1 . $_sql_2;
return $sql;
}
This code has worked. the SQL statement it generates is then used on the DB, and it’s responsible for one of the rows in the DB.
Even so, now it fails silently. The script works, otherwise.
here you can find complete copies of all three files used, and the log file.
As you can see, it’s not writing anything to the log after the custom function
and, when i put that last working file_put_contents() just after it, it stops working.
Any ideas? doing a php -f IPNrx.php gives no output, and logs an invalid transaction, like it should, but it doesn’t test that branch of the logic.
EDIT: there are three problems, two of them fatal, one insiduous.
First, the if statements should read if ($num != (count($keywords) - 1)), instead of if ($num != (count($keywords - 1)))
Second, the $db object is not inside the function’s scope, so i need to add global $db at the top of the function
Third, there’s an extra underscore near the end; $sql = $sql_1 . $_sql_2; should be $sql = $sql_1 . $sql_2;
Thanks a million guys. i’d never have found these without your help.
This line references a non-existent variable:
Should be:
Therefore, the query is invalid. You should check the output after executing the SQL query (
mysql_error(), for example).