Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:
- <?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();
- ?>
- header('Content-Type: application/json');
- echo json_encode($response);
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
- <form class="modal-content animate" method="post">
- <div class="container">
- <label><b>Username</b></label>
- <input type="text" id="usernameinput" placeholder="Enter username" name="uname" required>
- <label><b>Password</b></label>
- <input type="password" id="passwordinput" placeholder="Enter Password" name="psw" required>
- <button onclick="document.getElementById('id01').style.display='block'">Sign Up</button>
- <button type="button" id="loginsubmit" onclick="myLogin(document.getElementById('usernameinput').value, document.getElementById('passwordinput').value)">Login</button>
- </div>
- </form>
- function myLogin(username, password){
- var datasend=("user="+username+"&pwd="+password);
- $.ajax({
- url: 'makeUserEntry.php',
- type: 'POST',
- data: datasend,
- success: function(response, status) {
- if(response=="Username or Password did not match"){
- alert("Username or Password did not match");
- }
- if(response=="Connection Failure"){
- alert("Connection Failure");
- }
- else{
- localStorage.userid = response;
- window.location.href = "./maze.html"
- }
- },
- error: function(xhr, desc, err) {
- console.log(xhr);
- console.log("Details: " + desc + "nError:" + err);
- var response = xhr.responseText;
- console.log(response);
- var statusMessage = xhr.status + ' ' + xhr.statusText;
- var message = 'Query failed, php script returned this status: ';
- var message = message + statusMessage + ' response: ' + response;
- alert(message);
- }
- }); // end ajax call
- }
- <?php
- $MazeUser=$_POST['user'];
- $MazePass=$_POST['pwd'];
- //Connect to DB
- $servername="127.0.0.1";
- $username="root";
- $password="password";
- $dbname="infinitymaze";
- //Create Connection
- $conn = new MySQLi($servername, $username, $password, $dbname);
- //Check connetion
- if ($conn->connect_error){
- die("Connection Failed: " . $conn->connect_error);
- echo json_encode("Connection Failure");
- }
- $verifyUPmatchSQL=("SELECT * FROM mazeusers WHERE username LIKE '$MazeUser' and password LIKE '$MazePass'");
- $result = $conn->query($verifyUPmatchSQL);
- $num_rows = $result->num_rows;
- if($num_rows>0){
- $userIDSQL =("SELECT mazeuserid FROM mazeusers WHERE username LIKE '$MazeUser' and password LIKE '$MazePass'");
- $userID = $conn->query($userIDSQL);
- echo json_encode($userID);
- }
- else{
- echo json_encode("Username or Password did not match");
- }
- $conn->close();
- ?>
- }
Add Comment
Please, Sign In to add comment