首页 > 解决方案 > html表单值到mysql数据库

问题描述

我已经制作了一个基本的 html 页面来使用 nodejs 将电子邮件值发送到 mysql,但是它不起作用,当我在 cmd node test.js 上运行它时我没有看到任何错误,我在我的 localhost cmd 上也没有看到任何错误。

我的html

<!DOCTYPE html>
<html>
<head>
    <title> email lol </title>
    <script src= "test.js"> </script>
</head>
<body>
    <input id="userEmail" type = "email" > </input>
    <input type = "submit" onclick="sendEmail();"> </input>
</body>
</html>

我的节点

var mysql = require('mysql');

var con = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "Bionicle123!",
    database: "account"
});

con.connect(function(err)
{
    if (err) throw err;
    console.log("Connected!");
});

function sendEmail()
{
    var gebruikerEmail = document.getElementById("userEmail").value;
    var sqlGebruikerEmail = "INSERT INTO persoon (email) VALUES (gebruikerEmail)";

    con.query(sqlGebruikerEmail, function (err, result)
    {
        if (err) throw err;
        console.log("1 record inserted");
    });
}

标签: javascripthtmlmysqlnode.js

解决方案


推荐阅读