I’m trying to make a PayPal IPN file but the response won’t be inserted into the database. After a little debugging i found that my function has one error but i don’t know which one.
It seems that the following code is wrong, but i don’t know why. It looks good to me. Am i doing something wrong?
<?php
function check_price($price, $id) {
$valid_price = false;
$sql = $wpdb->get_results("SELECT * FROM `webc_products` WHERE id = '$id'");
foreach ( $sql as $prod ) {
$num = (float)$prod->amount;
if($num == $price){
$valid_price = true;
}
}
return $valid_price;
}
$a = check_price(0.01, 1);
?>
Also, i tried the code outside the function and somehow it works.
You’re function is accessing the
$wpdbobject without actually having access to it (variable scope).Either pass it as a parameter to your function (I’d recommend that) or declare it as global in your function.