ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php – XML解析错误:找不到根元素位置

2019-07-17 09:30:46  阅读:175  来源: 互联网

标签:php html5 web-applications xml-parsing xml


所以我正在制作一个简单的登录/注册Web应用程序,但我不断收到以下错误:

XML Parsing Error: no root element found Location: file:///C:/xampp/htdocs/EdgarSerna95_Lab/login.html Line Number 37, Column 3:   

XML Parsing Error: no root element found Location: file:///C:/xampp/htdocs/EdgarSerna95_Lab/php/login.phpLine Number 37, Column 3:

这是我的login.php

<?php
header('Content-type: application/json');

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jammer";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    header('HTTP/1.1 500 Bad connection to Database');
    die("The server is down, we couldn't establish the DB connection");
}
else {
    $conn ->set_charset('utf8_general_ci');
    $userName = $_POST['username'];
    $userPassword = $_POST['userPassword'];

    $sql = "SELECT username, firstName, lastName FROM users WHERE username = '$userName' AND password = '$userPassword'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $response = array('firstName' => $row['firstNameName'], 'lastName' => $row['lastName']);
        }
        echo json_encode($response);
    }
    else {
        header('HTTP/1.1 406 User not found');
        die("Wrong credentials provided!");
    }
}
$conn->close();
?>

我已经做了一些关于xml解析错误的研究,但我仍然无法让我的项目工作,我试过谷歌Chrome和Firefox

解决方法:

AHA!今天得到了这个原因,这会让我看起来很傻,但有一天可能会帮助别人.

在我的机器上设置了Apache服务器,用PHP等等……我收到了这个错误…然后意识到原因:我点击了有问题的HTML文件(即包含Javascript / JQuery的文件),所以浏览器中的地址栏显示“file:/// D:/apps/Apache24/htdocs/experiments/forms/index.html”.

实际使用Apache服务器(假设它正在运行等)所要做的就是在浏览器的地址栏中输入“http://localhost/experiments/forms/index.html”.

在缓解方面,我到目前为止一直在使用“index.php”文件,只是改为“index.html”文件.有点困难,因为对于前者,你必须使用localhost“正确”访问它.

标签:php,html5,web-applications,xml-parsing,xml
来源: https://codeday.me/bug/20190717/1487195.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有