【发布时间】:2017-08-03 00:47:12
【问题描述】:
所以我正在制作一个简单的登录/注册 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 解析错误进行了一些研究,但我仍然无法使我的项目正常运行,我尝试使用 Google Chrome 和 Firefox
【问题讨论】:
-
您必须使用 URL 和本地网络服务器打开页面/脚本。将它们作为本地文件打开不会执行 PHP,而是输出 PHP 源代码,请检查浏览器的源代码视图。
标签: php xml html web-applications xml-parsing