Guest User

Untitled

a guest
Jan 2nd, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. XML Parsing Error: no root element found Location: file:///C:/xampp/htdocs/EdgarSerna95_Lab/login.html Line Number 37, Column 3:
  2.  
  3. XML Parsing Error: no root element found Location: file:///C:/xampp/htdocs/EdgarSerna95_Lab/php/login.phpLine Number 37, Column 3:
  4.  
  5. <?php
  6. header('Content-type: application/json');
  7.  
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "";
  11. $dbname = "jammer";
  12.  
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17. header('HTTP/1.1 500 Bad connection to Database');
  18. die("The server is down, we couldn't establish the DB connection");
  19. }
  20. else {
  21. $conn ->set_charset('utf8_general_ci');
  22. $userName = $_POST['username'];
  23. $userPassword = $_POST['userPassword'];
  24.  
  25. $sql = "SELECT username, firstName, lastName FROM users WHERE username = '$userName' AND password = '$userPassword'";
  26. $result = $conn->query($sql);
  27.  
  28. if ($result->num_rows > 0) {
  29. while($row = $result->fetch_assoc()) {
  30. $response = array('firstName' => $row['firstNameName'], 'lastName' => $row['lastName']);
  31. }
  32. echo json_encode($response);
  33. }
  34. else {
  35. header('HTTP/1.1 406 User not found');
  36. die("Wrong credentials provided!");
  37. }
  38. }
  39. $conn->close();
  40. ?>
  41.  
  42. header('Content-Type: application/json');
  43. echo json_encode($response);
  44.  
  45. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  46. <form class="modal-content animate" method="post">
  47. <div class="container">
  48. <label><b>Username</b></label>
  49. <input type="text" id="usernameinput" placeholder="Enter username" name="uname" required>
  50. <label><b>Password</b></label>
  51. <input type="password" id="passwordinput" placeholder="Enter Password" name="psw" required>
  52. <button onclick="document.getElementById('id01').style.display='block'">Sign Up</button>
  53. <button type="button" id="loginsubmit" onclick="myLogin(document.getElementById('usernameinput').value, document.getElementById('passwordinput').value)">Login</button>
  54. </div>
  55. </form>
  56.  
  57. function myLogin(username, password){
  58. var datasend=("user="+username+"&pwd="+password);
  59. $.ajax({
  60. url: 'makeUserEntry.php',
  61. type: 'POST',
  62. data: datasend,
  63. success: function(response, status) {
  64. if(response=="Username or Password did not match"){
  65. alert("Username or Password did not match");
  66. }
  67. if(response=="Connection Failure"){
  68. alert("Connection Failure");
  69. }
  70. else{
  71. localStorage.userid = response;
  72. window.location.href = "./maze.html"
  73. }
  74. },
  75. error: function(xhr, desc, err) {
  76. console.log(xhr);
  77. console.log("Details: " + desc + "nError:" + err);
  78. var response = xhr.responseText;
  79. console.log(response);
  80. var statusMessage = xhr.status + ' ' + xhr.statusText;
  81. var message = 'Query failed, php script returned this status: ';
  82. var message = message + statusMessage + ' response: ' + response;
  83. alert(message);
  84. }
  85. }); // end ajax call
  86. }
  87.  
  88. <?php
  89. $MazeUser=$_POST['user'];
  90. $MazePass=$_POST['pwd'];
  91.  
  92.  
  93. //Connect to DB
  94. $servername="127.0.0.1";
  95. $username="root";
  96. $password="password";
  97. $dbname="infinitymaze";
  98. //Create Connection
  99. $conn = new MySQLi($servername, $username, $password, $dbname);
  100. //Check connetion
  101. if ($conn->connect_error){
  102. die("Connection Failed: " . $conn->connect_error);
  103. echo json_encode("Connection Failure");
  104. }
  105. $verifyUPmatchSQL=("SELECT * FROM mazeusers WHERE username LIKE '$MazeUser' and password LIKE '$MazePass'");
  106. $result = $conn->query($verifyUPmatchSQL);
  107. $num_rows = $result->num_rows;
  108. if($num_rows>0){
  109. $userIDSQL =("SELECT mazeuserid FROM mazeusers WHERE username LIKE '$MazeUser' and password LIKE '$MazePass'");
  110. $userID = $conn->query($userIDSQL);
  111. echo json_encode($userID);
  112. }
  113. else{
  114. echo json_encode("Username or Password did not match");
  115. }
  116.  
  117. $conn->close();
  118. ?>
  119.  
  120. }
Add Comment
Please, Sign In to add comment