JavaScript Trying to call PHP script from Javascript If statement

I have a form which gets validated by javascript. In one of the if statements, in the final condition (when everything else has been validated) I would like to put my PHP script that updates SQL with one of the passwords.

This is the final validation:

function passwordCheck() {
    var password = '<?php echo $password; ?>';
    if (document.passwordform.inputedPassword.value == password)
    {
        if (document.passwordform.Password1.value == document.passwordform.Password2.value)
        {
            *********************************************************
        } else 
        {
            document.getElementById("equalpasswords1").innerHTML = "Passwords should be equal";
            document.getElementById("equalpasswords2").innerHTML = "Passwords should be equal";
        }
    } else 
    {
        text = "Insert a correct password";
        document.getElementById("editpassword").innerHTML = text;
    }
    return true;
}

And I would like to insert a call to my PHP script where the stars are. How could I do this? I read that you can't insert PHP into javascript, so it has to be an external PHP file. My SQL update code is this one:

<?php              
$x = $_POST['Password2'];

define('DB_NAME', 'Students');
define('DB_USER', 'Students');
define('DB_PASSWORD', 'Password');
define('DB_HOST','HOST');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!link) {
  die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
  die('Can\'t use'. DB_NAME. ': ' . mysql_error());
}    


$result = "UPDATE  `1956218_students`.`Students` SET  `Password` =  '$x' WHERE  `Students`.`StudEmail` = '$email'  ";
if (!mysql_query($result)) {
die('error: ' .mysql_error());
} 

?>
Answer:1

I have some <List> connected component which passes a lot of attributes to <ListItem> components. It is getting to the point where a refactor is needed because too many attributes are ...

I have some <List> connected component which passes a lot of attributes to <ListItem> components. It is getting to the point where a refactor is needed because too many attributes are ...

  1. redux list performance

I am planning on adding the javascript Notifications API functionality to a web app I am building. I took a look at the example from the MDN site: function spawnNotification(theBody, theIcon, ...

I am planning on adding the javascript Notifications API functionality to a web app I am building. I took a look at the example from the MDN site: function spawnNotification(theBody, theIcon, ...

  1. using icon font in sketch
  2. using icon font
  3. using icon font as background image
  4. using font icon in css
  5. display icon using font

I'm working with the import function, I wish use an import like for css, I mean "import './file.css'" then all the css attributes are diffused in the file. I have tried the same with ReactJS but it ...

I'm working with the import function, I wish use an import like for css, I mean "import './file.css'" then all the css attributes are diffused in the file. I have tried the same with ReactJS but it ...

  1. import variables from another file python
  2. import variables from another file matlab
  3. import variables from scss file
  4. import variables from module python
  5. import variables from another file javascript
  6. import variables from file bash
  7. import variables from other files python
  8. import variables from a file python
  9. import variables from another file powershell
  10. import variables from text file python
  11. import variables from another class java
  12. import variables from excel to matlab
  13. import variables from another file bash
  14. import variables from settings django
  15. import variables from another python script
  16. import variables from workspace to simulink
  17. import variables from another file js
  18. import variables from another file java
  19. import variables from file powershell
  20. import variables from module

I face difficulties to write reducers for Redux. Specifically I end up wrapping a lot of my state manipulation in .map, .slice etc. When the structure of my state object grows larger, the reducers ...

I face difficulties to write reducers for Redux. Specifically I end up wrapping a lot of my state manipulation in .map, .slice etc. When the structure of my state object grows larger, the reducers ...