Siz muhtemelen db bağlantısı için bir sınıf kullanıyorsunuz sanırım. PDO ile bu şekilde bir örnek yaptım sizin için;
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$db->query('SET NAMES utf8');
$xml = simplexml_load_file('http://www.tcmb.gov.tr/kurlar/today.xml');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach ($_POST['currency'] as $key => $value) {
$query = $db->prepare('UPDATE `currency` SET `value` = ? WHERE `key` = ?');
$query->bindParam(1, $value, PDO::PARAM_STR);
$query->bindParam(2, $key, PDO::PARAM_STR);
$query->execute();
}
header('Location: currency.php');
exit();
}
$query = $db->query('SELECT `key` FROM currency', PDO::FETCH_ASSOC);
$rows = $query->fetchAll();
$myCurrency = array();
foreach ($rows as $row) {
array_push($myCurrency, $row['key']);
}
echo '<form action="" method="POST">';
echo '<table>';
foreach ($xml->Currency as $item) {
$attr = $item->attributes();
if (in_array((string) $attr->CurrencyCode, $myCurrency)) {
echo '<tr>';
echo '<td>' . $attr->CurrencyCode . '</td>';
echo '<td><input type="text" name="currency[' . $attr->CurrencyCode . ']" value="' . $item->BanknoteSelling . '"></td>';
echo '</tr>';
}
}
echo '<tr>';
echo '<td colspan="2"><button type="submit">Güncelle</button></td>';
echo '</tr>';
echo '</table>';
echo '</form>';