0

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.

Odess4
  • 420
  • 5
  • 17
  • 1
    It appears you should read the answer to this post: https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – Randy Casburn Jan 25 '19 at 22:07
  • Do I need to separate my NodeJd code from my HTML code ? – Odess4 Jan 25 '19 at 22:18
  • Firstly, I second what @RandyCasburn said above. You need to follow proper protocol for a NodeJS app. Are you using an IDE? I suggest using VSCode as it has great integration for NodeJS apps. – BILL WAGNER Jan 25 '19 at 22:39
  • 1
    You need to separate your **Server** thinking from your **Client** thinking. Server side JavaScript code executed by Node. it may have the purpose of serving HTML to the client, so HTML may be necessary there. Client side JavaScript is executed by the browser and has no access whatsoever to the "stuff" available on the server (like MySQL). It is deeper than _Do I need to separate my NodeJd code from my HTML code ?_ – Randy Casburn Jan 25 '19 at 22:43
  • I'm using Atom Text Editor – Odess4 Jan 25 '19 at 22:43
  • thank you @RandyCasburn for your advices , i just started diging into web technologies , what do i need to do first ? – Odess4 Jan 25 '19 at 22:45
  • Read everything here: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web – Randy Casburn Jan 25 '19 at 22:45

0 Answers0