I am returning an array of results which I put into a foreach loop and each result checks against a single amount. As long as the condition is met it should insert rows. However, no data is ever inserted into the database but the error logs are also empty ie: I get no errors.
foreach ($invoices as $invoice) {
if ($invoice->amount <= $this->amount) {
$stmt = $db->prepare("INSERT INTO `payment_link` (`amount`) VALUES (:amount)");
$stmt->bindValue(":amount", $invoice->amount, PDO::PARAM_STR);
$stmt->execute();
}
}
print_r($invoices) gives me:
Array ( [0] => App\Models\Invoice Object ( [customer_id] => [description] => [date_created] => [amount] => 300.00 [total:App\Models\Invoice:private] => [invoice_id] => [line_description] => [line_amount] => [errors] => Array ( ) ) [1] => App\Models\Invoice Object ( [customer_id] => [description] => [date_created] => [amount] => 500.00 [total:App\Models\Invoice:private] => [invoice_id] => [line_description] => [line_amount] => [errors] => Array ( ) ) ) Array ( [0] => App\Models\Invoice Object ( [customer_id] => [description] => [date_created] => [amount] => 300.00 [total:App\Models\Invoice:private] => [invoice_id] => [line_description] => [line_amount] => [errors] => Array ( ) ) [1] => App\Models\Invoice Object ( [customer_id] => [description] => [date_created] => [amount] => 500.00 [total:App\Models\Invoice:private] => [invoice_id] => [line_description] => [line_amount] => [errors] => Array ( ) ) )
if ($invoice->amount <= $this->amount) {condition, if itsTRUE, second checkprint_r($invoices)what r u getting and share the result.$this->amountis 800 and$invoice->amountare 300 and 500. If I echo out $invoice->amount then I get 300 and 500 so it is true. Will post theprint_rin my original question now..VALUES (:amount)withVALUES (?)and try.