I got an associative array that looks like
$rates = array (
'AUD' => '0.5',
'BRL' => '1.2',
'CAD' => '0.6',
'CHF' => '0.4',
'CZK' => '1.5',
);
I want to put this array in mysql so that i can use the rates to make an currency converter. mine question is how do you do that i tried
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "eurotoforgein";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$table = 'rates';
$keys = implode(', ', array_keys($rates));
$values = "'" . implode("','", array_values($rates)) . "'";
$sql = 'insert into '.$table.'('.$keys.') values ('.$values.')';
if(!$result = $conn->query($sql)){
die('There was an error running the query [' . $conn->error . ']');
}
else{
echo "Data inserted.";
}
the error i got is There was an error running the query [Unknown column 'AUD' in 'field list'] for the table used
// sql to create table
$sql = "CREATE TABLE eurotoforgein (
COUNTRY VARCHAR(6),
RATES FLOAT(10)
)";
if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
any help is welcome thanks
INSERT INTO eurotoforgein (COUNTRY, RATES) VALUES ('AUD', 0.5), notINSERT INTO eurotoforgein (AUD) VALUES (0.5)