内部服务器错误500与jquery.min.js

时间:2017-09-09 08:44:41

标签: php jquery

我是PHP的新手。现在我正在构建一个简单的登录注销系统。在尝试登录系统时,我使用jquery.min.js:4获得了内部服务器错误。这是我的代码: 指数:

<!-- Login Form -->
<form method="post" id="loginForm">
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="#loginHeading" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="loginHeading">Login Form</h4>
      </div>
      <div class="modal-body">
          <div id="loginMessage"></div>
          <div class="form-group">
            <label for="email">Email: </label>
            <input type="email" id="email" name="email" class="form-control" required>
          </div>
          <div class="form-group">
            <label for="pass">Password: </label>
            <input type="password" id="pass" name="pass" class="form-control" required>
          </div>
          <div class="row">
            <div class="checkbox" >
              <div class="pull-left" style="padding-left:20px">
                <a href="#" data-dismiss="modal" data-target="#forgetPass" data-toggle="modal">Forget password?</a>
              </div>
              <label class="pull-right" style="padding-right:20px"><input type="checkbox" name="remember" value=""> Remember me</label>
            </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success pull-left" data-dismiss="modal" data-toggle="modal" data-target="#signUp">Register</button>
        <button type="submit" class="btn myBtn">Login</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

脚本:

 $("#loginForm").submit(function(event) {
    event.preventDefault();
    var dataPost= $(this).serializeArray();
    $.ajax({
      url: '4-logIn.php',
      type: 'POST',
      data: dataPost,
      success:function(data){
        if (data == "success") {
          window.location("mainPageLogin.php");
        }
        else {
          $("#loginMessage").html(data);
        }
      },
      error: function(data){
        $('#loginMessage').html('<div class="alert alert-danger"><h5>Error in connection with loginForm</h5></div>');
      }
    });
  });

4的login.php: ``

<?php
  session_start();
  include '0-connection.php';

  $error='';

  $email=filter_var($_POST["email"],FILTER_SANITIZE_EMAIL);
  $pass=filter_var($_POST["pass"],FILTER_SANITIZE_STRING);

  // Query
  $email=mysqli_real_escape_string($link,$email);
  $pass=mysqli_real_escape_string($link,$pass);
  $pass=hash('sha256',$pass);

  $sql="SELECT * FROM users WHERE email='$email' AND password='$pass' AND activation='activated'";
  $result=mysqli_query($link, $sql);
  if (!$result) {
    echo "<div class='alert alert-danger'>Error running the query to take user login</div>";
    exit;
  }
  $count= mysqli_num_rows($result);
  if ($count !== 1) {
    $error="<div class='alert alert-danger'><strong>ERROR:</strong> Wrong username or password. Please try again or Do you want to <a href='#' data-dismiss='modal' data-target='#signUp' data-toggle='modal'>Sign up</a></div>";
    echo $error;
  }
  else {
    // Set session
    $row=mysqli_fetch_array($result, MYSQLI_ASSOC);
    $_SESSION['user_id']=$row['user_id'];
    $_SESSION['username']=$row['username'];
    $_SESSION['email']=$row['email'];
    // Check remember me Box
    if (empty($_POST['remember'])) {
      echo "success";
    }
    else {

    }

  }
  ?>

这是我的错误: demonstration web response

请在答案中更具体,因为我是编程新手。谢谢你的阅读。

1 个答案:

答案 0 :(得分:0)

4-logIn.php中的错误,if (!result) {必须更改为if (!$result) {