M
M
Mykola Dudyak2020-06-04 15:38:48
MySQL
Mykola Dudyak, 2020-06-04 15:38:48

How to format data input and output correctly?

I have a local database and I need to send a request to enter data through textarea and vivisti data in the Chrome web program. The code of the query program is:

$(document).ready(function() {
    $('#btn_submit').click(function(e) {
        e.preventDefault();

        //var input = $('#input').val();

var mysql = require("mysql");

var conn = mysql.createConnection({
    host: "localhost",
    database: "electronic_dictionary",
    user: "admin",
    password: "admin"
});
conn.connect(function(err) {
    if (err) throw err;
    console.log("Connected!");
});
const sql = "SELECT * FROM `tlum` WHERE `tlum_name` = ?";
const filter = $('#input').val();
conn.query(sql, filter, function (err, result) {
    if(err) console.log(err);
    console.log(result);
})
        

conn.end(err => {
    if (err) throw err;
   console.log("CLOSSED!");
})

Code of the program itself
<!DOCTYPE html>
<html>
<head>
    <script src="jquery.js"></script>
    <script src="Node.js"></script>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="style.css">
</head>
<body>

        <header>
            <textarea id="input"></textarea>
            <input id="btn_submit" type="submit"><br>


        </header>
        <article>
            <div id="result" ></div>


        </article>

        <footer>
            ©
            <span>2020</span>
             Good Word Guide
        </footer>
    </div>
</body>
</html>

And the program itself
5ed8eb4f8bf0a841514585.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebDev, 2020-06-04
@kirill-93

mysql and nodejs don't work in the browser. They work on the server. You have server and client code in one file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question