Hello i have problem with getting input from html to node and send it to databse. What I am getting now is input type "undefined". So if someone could help me I would really preciate it. down here is my code html and node.js
| |
| |
| |
\ /
\ /
\ /
\/
HTML
<form action="database" method="POST">
<div class="form-group" id="test">
<label for="fname">First name</label>
<input type="text" id="fname" placeholder="First name: " name="fname">
</div>
<div class="form-group">
<label for="lname">Last name</label>
<input type="text" id="lname" placeholder="Last name: " name="lname">
</div>
<div class="form-group">
<label for="state">state: </label>
<input type="text" id="state" name="state" placeholder="sate: ">
</div>
</form>
NODE.js
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "test"
});
var fname = req.body.fname;
var lname = req.body.lname;
var state = req.body.state;
con.connect(function(err) {
if (err) throw err;
var sql = `INSERT INTO customers (c_fname, c_lname, c_state) VALUES ("${fname}", "${lname}", "${state}")`;
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted, ID: " + result.insertId);
});
});