0

I want to pass data in Ajax but when running the function it appears the Internal Server Error when I inspect the element. I'm building a login form but when clicking the button of login it appears the Internal Server Error.

     function login (){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        console.log("Test2");
        document.getElementById("IdForm").innerHTMl = this.responseText;
        console.log("Test3");
        alert (this.responseText);
    }
};

xhttp.open("POST", "PHP/login.php", true);
var data = new FormData(document.getElementById("IdForm"))
console.log("Status500")
xhttp.send(data);

return false;
    }

I here you have the PHP code:

     <?php
      $servername = "localhost";
      $username = "*****";
      $password = "******";
      $dbname = "*******";
      //create connection
      $conn = new mysqli ($servername, $username, $password, $dbname);
     //Check connection

     if ($conn ->connect_error) 
     {
     die("connection failed:" . $conn -> connect_error);
      }
     $sql = "SELECT * FROM accounts";
     $result = $conn ->query($sql);
     $out = "";
     $rc = "";
     if ($result->num_rows > 0)
     {
    while($row = $result -> fetch_assoc())
     {

    echo "<p> " . $_POST ["username"] . "</p>";
    if (($row ["username"] == $_POST ["username"]) and $row ["password"] == $_POST ["password"])
    header('Location: ok.html');
    else
    echo "User not valid";
     }
     } else{
    echo "0 results";
     }
     */
      ?>
B.Casals
  • 7
  • 2
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Dharman Nov 17 '19 at 10:42

1 Answers1

0

It looks like you have a closing comment-tag */ without a comment start. For PHP is this an syntax error/typo. If you remove the tag it probably works

Martijn
  • 29
  • 1
  • 6