I Have two HTML Pages , the first One is takeInput.html where the user should say if he's a client or an Owner .He is then redirected in a page to achieve its registration regarding the choice that he did ( client.html or owner.html). Here is Client.html Page:
<form >
<p>First Name : </p>
<input type="text" name="firstName" /><br/>
<p>Last Name : </p>
<input type="text" name="lastName" ><br/>
<p>Email : </p>
<input type="text" name="email" ><br/>
<p>City : </p>
<input type="text" name="city" ><br/>
<input type="button" onclick="Hello()" value="OK">
</form>
<script>
function Hello(){
var fName = document.getElementsByName("firstName").value;
var lName = document.getElementsByName("lastName").value;
var em = document.getElementsByName("email").value;
var cit = document.getElementsByName("city").value;
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database:"CAR_WASH"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql="INSERT INTO CLIENTS(NAME,EMAIL,CITY) VALUES ?";
var values=[[fName,em,cit]];
con.query(sql,values,function(err,result){
if(err) throw err;
alert('Well done !');
});
});
}
</script>
I want to insert the Data in the CLIENTS TABLE , But When i run the script below it doesn't display anything ... Here is the script:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database:"CAR_WASH"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql="SELECT * FROM CLIENTS";
con.query(sql,function(err,result){
if(err) throw err;
console.log(result);
});
});
Thank you in advance.