2

Hypothetical here: Let's say that you have a JavaScript file that uses jQuery to get input from the user. For example:

var $input = 0;
var buttonClick = function() {
  $('.button').click(function() {
     $input = $('input').val();
  });
}
$(document).ready(buttonClick());

But what if you want to use sql to see if the input matches a password in a database

  1. How would you tell the sql script to run after you click the button?
  2. How would you share the $input variable the sql script so it could check it against the database?
Null Spark
  • 35
  • 8
  • 1
    1. Send a postback (ie 'AJAX') to the server. 2. Send the value to the server as part of said postback; and then use it on said server. The client can then react according to the server response. (I highly recommend reading up about password management/security before implementing anything that uses them: there are some well-established do's and don'ts.) – user2864740 Nov 28 '15 at 23:37
  • In addition to the previous comments. If you are comfortable with javascript, consider looking into `express` as the url router/controller to handle the postback, `knex` for the database interface to make sql queries, and `node` as the backend. – jmunsch Nov 28 '15 at 23:40
  • There is a basic example of what that would look like here, it also uses `bookshelf` but its not necessary. See: http://stackoverflow.com/questions/32933105/express-insert-values-into-mysql-database – jmunsch Nov 28 '15 at 23:48

2 Answers2

0

If you wan't to check Password when your client click on the button , you need to use Ajax and call a Php function.

So when your client click on the button, Jquery call the PHP script and the PHP script call Mysql. After Mysql give a response to Php who send Data to Jquery (true or false in this case).

0
var buttonClick = function() {
   $('.button').click(function() {
       $.post( "script.php", { Username: "Your Name", Password: "Password" })
          .done(function( data ) {
               alert( "Data Send: " + data );
// In data you have a response you got from the php script 
   });
 });
}