Mr Chris Posted July 14, 2009 Share Posted July 14, 2009 Hello, I have a function i've written to output the hidden fields that paypal requires to process a payment like so using a foreach function Paypal($Database) { if($this->NumberOfItems() > 0){ $total = 0; $output = '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="??????????????"> <input type="hidden" name="currency_code" value="GBP"> '; $i = 1; foreach ($this->Cart as $ProductID => $Qty){ $result = $Database->query('SELECT * FROM shop WHERE id = '.$ProductID); $row = $result->fetch(); $price = sprintf('£%.2f', $row['price']); $priceUnit = sprintf($row['price']); $rowTotal = sprintf('£%.2f', $row['price'] * $Qty); $total += $row['price'] * $Qty; $output .= <<<ROW <input type="hidden" name="item_name_{$i}" value="{$row['description']}"> <input type="hidden" name="amount_{$i}" value="{$priceUnit}"> <input type="hidden" name="quantity_{$i}" value="{$Qty}"> ROW; $i++; } $total = sprintf('£%.2f', $total); $output .= <<<END <input class="paybtn" type="submit" value="Pay"> </form> END; return $output; } } Now this works great, but at the same time as running this function and foreach statement to output the hidden fields I'd also like to INSERT the data into a database table row-by row. Is this possible? The table would just be a simple one like so: items -------- id (auto inc) description amount quantity But i'm not sure how to include this in the function so it does this? Link to comment https://forums.phpfreaks.com/topic/165943-insert-into-database-with-foreach/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.