問題描述
所以我正在制作一個簡單的登錄/注冊網絡應用程序,但我不斷收到以下錯誤:
So I'm making a simple login/registration web application but I keep getting the following error:
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
here is my 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 解析錯誤進行了一些研究,但我仍然無法使我的項目正常工作,我嘗試過使用 Google Chrome 和 Firefox
I've done some research about xml parsing errors but I still cant manage to make my project work, ive tried with Google Chrome and Firefox
推薦答案
啊哈!今天得到這個的原因會讓我看起來很傻,但可能有一天會幫助某人.
AHA! Got this today for a reason which will make me look pretty silly but which might one day help someone.
在我的機器上設置了一個 Apache 服務器,使用 PHP 等等......我收到這個錯誤......然后意識到原因:我點擊了有問題的 HTML 文件(即包含 Javascript/JQuery),所以瀏覽器地址欄顯示file:///D:/apps/Apache24/htdocs/experiments/forms/index.html".
Having set up an Apache server on my machine, with PHP and so on... I got this error... and then realised why: I had clicked on the HTML file in question (i.e. the one containing the Javascript/JQuery), so the address bar in the browser showed "file:///D:/apps/Apache24/htdocs/experiments/forms/index.html".
要實際使用 Apache 服務器(假設它正在運行等),您需要做的是 "http://localhost/experiments/forms/index.html" 在瀏覽器的地址欄中.
What you have to do to actually use the Apache server (assuming it's running, etc.) is go "http://localhost/experiments/forms/index.html" in the browser's address bar.
在緩解方面,我一直使用index.php"文件,只是更改為index.html"文件.有點問題,因為對于前者,您必須使用本地主機正確"訪問它.
In mitigation I have up to now been using an "index.php" file and just changed to an "index.html" file. Bit of a gotcha, since with the former you are obliged to access it "properly" using localhost.
這篇關于XML 解析錯誤:找不到根元素位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!