Php 为什么服务器响应为加载资源失败:服务器响应状态为500(内部服务器错误)?我怎样才能解决它?

Php 为什么服务器响应为加载资源失败:服务器响应状态为500(内部服务器错误)?我怎样才能解决它?,php,sql,ajax,Php,Sql,Ajax,我想在Ajax中传递数据,但在运行函数时,检查元素时会出现内部服务器错误。我正在构建一个登录表单,但当单击登录按钮时,会出现内部服务器错误 function login (){ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log(

我想在Ajax中传递数据,但在运行函数时,检查元素时会出现内部服务器错误。我正在构建一个登录表单,但当单击登录按钮时,会出现内部服务器错误

     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;
    }
我这里有PHP代码:

     <?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";
     }
     */
      ?>


看起来您有一个结束注释标签
*/
,没有注释开始。对于PHP来说,这是一个语法错误/输入错误。如果您删除标签,它可能会起作用

这是否回答了您的问题?