javascript - 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");
});
}
解决方案
推荐阅读
- java - 我的应用程序显示“应用程序可能在其主线程上做了太多工作。”,我不知道代码的哪一部分导致了这种情况
- r - 使用 YahooQF 下载股票目标价格
- swift - 你如何让一个枚举可以通过它的案例名称而不是它的原始值来解码?
- javascript - TypeError:this.props.history 不是 Navigation 共享组件中的函数
- ruby-on-rails - 作为可投票的宝石,我将如何显示喜欢/赞成的帖子
- scheme - 谁能解释这段代码中发生了什么?
- regex - 通过正则表达式将逗号插入数字
- r - R ggplot2 X 轴排序问题——按字母顺序排列
- c++ - 我可以将一个类中的 lambda 函数分配给另一个类中的函数指针吗
- python - 如何用用户输入替换字符串的元素