2021年1月2日星期六

How do I connect to the mysql server from the html page upon button click? [duplicate]

I am trying to connect to MYSQL database.

My code:

<button id="go" onclick="register()">Go</button>    <script type="text/javascript">        function register(){          var mysql = require('mysql');        var con = mysql.createConnection({          host: "localhost",          user: "yourusername",          password: "yourpassword"      });        con.connect(function(err) {          if (err) throw err;          console.log("Connected!");      });  }  </script>  

When I open console it shows:

Uncaught ReferenceError: require is not defined  

I have nodejs installed and have also installed MYSQL from cmd using the command:

npm install mysql  

What is wrong here?

https://stackoverflow.com/questions/65546431/how-do-i-connect-to-the-mysql-server-from-the-html-page-upon-button-click January 03, 2021 at 11:44AM

没有评论:

发表评论