const mysql = require("mysql2");

const savePostData = (req, res) => {
    const connection = mysql.createConnection({
    host: process.env.MARIA_HOST,
    user: process.env.MARIA_USER,
    password: process.env.MARIA_PASS,
    database: process.env.MARIA_DBNM
    });

    connection.connect((err) => {
    if (err) {
        console.error('Error connecting to the database:', err);
        return;
    }
    console.log('Connected to the MariaDB database.');
    });

    const data = req.body;

    const query = `INSERT INTO tst (name, email) VALUES (?, ?)`;
    const values = [data.name, data.email];

    connection.query(query, values, (err, results) => {
        if (err) {
        console.error('Error inserting data:', err);
        res.status(500).send('Internal Server Error');
        return;
        }
        res.status(200).send('Data inserted successfully');
    });
}
module.exports = savePostData;