I have the following html form:
<form id="shipnow-form" class="form-signin" action="" method="POST" onsubmit="submitForm(event)">
<ul id="progressbar">
<li>Your Personal Details</li>
<li>Thank You</li>
</ul>
<br>
<br>
<br>
<div class="text-center mb-4">
</div>
<div class="form-label-group">
<input type="Name" name="name" id="inputName" class="form-control" placeholder="Name" required autofocus>
<label for="inputName">Name</label>
</div>
<div class="form-label-group">
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required>
<label for="inputEmail">Email</label>
</div>
<br>
<button class="btn btn-lg btn-primary btn-block" style="background-color:#d40511; border-style:hidden;" type="submit" ><b>Proceed</b></button>
</form>
I have been given the following codes to connect to the SQL database:
//Create connection
var conn = mysql.createConnection({
host: "abcd.mysql.database.azure.com",
user: "abcd@seft",
password: "asdfghjk",
database: "salesoffer",
port: "3306",
});
var sql = "INSERT INTO sales(name, email) VALUES('${name}', '${email}')";
I have tried using NodeJS and ran the following code: app.js
const mysql = require('mysql');
//Create connection
var conn = mysql.createConnection({
host: "abcd.mysql.database.azure.com",
user: "abcd@seft",
password: "asdfghjk",
database: "salesoffer",
port: "3306",
});
//connect to mysql
conn.connect(function(err) {
if(err) throw err;
console.log("MYSQL Connected");
var sql = "INSERT INTO sales(name, email) VALUES('${name}', '${email}')";
});
I am trying to connect the html form to the SQL database. This assignment is part of my internship, so I am sourcing for quick solutions from anyone who is expert in this. The SQL database has already been created by the company, and I am provided with 2 code snippets, and asked to connect the html form inputs to the database. For the company's protection, I have replaced the database connection code hostname and other details.
I have seen many solutions involving the use of PHP language, but the 2 code snippets don't seem to be of PHP language, and seems more like NodeJS javascript.
When I run app.js, it returns an error:
throw err; // Rethrow non-MySQL errors
Error: UNKNOWN_CODE_PLEASE_REPORT: Client with IP address '49.245.120.139' is not allowed to connect to this MySQL server.
at Handshake.Sequence._packetToError (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
--------------------
at Protocol._enqueue (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/Users/dhlmacbookpro/Downloads/ShipNow/node_modules/mysql/lib/Connection.js:116:18)
at Object.<anonymous> (/Users/dhlmacbookpro/Downloads/ShipNow/database.js:14:6)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'UNKNOWN_CODE_PLEASE_REPORT',
errno: 9000,
sqlMessage: "Client with IP address '49.245.120.139' is not allowed to connect to this MySQL server.",
sqlState: 'HY000',
fatal: true
I am not sure if I am on the right track by using NodeJS, since customers don't use terminals when they browse a website.
Also, I am not sure if its a database error that it should have allowed my computer to connect to it, or if it is because I am using the wrong approach to connect to the database.