weixin_33709590 2019-09-26 15:29 采纳率: 0%
浏览 45

Ajax在登录页面上提交

I am new to the PHP. I am trying to code a project using PHP and Ajax to logging into another page. But in Ajax query some parts are not executing that means it check every thing inside the Ajax query part but shows always "Wrong combination" in alert whenever it success.

Here is the code that I tried:

Logging page HTML would be:

form method="POST" class="form-signin">
                        <div class="account-logo">
                            <img src="assets/img/logo-dark.png" alt="">
                        </div>
                        <div class="form-group">
                            <label> Email</label>
                            <input type="email" name="email" id="email" autofocus="" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>Password</label>
                            <input type="password" name="password" id="password" class="form-control">
                        </div>
                        <div class="form-group text-right">
                            <a href="forgot-password.html">Forgot your password?</a>
                        </div>
                        <div class="form-group text-center">
                            <input type="button" onClick="sendContact();" class="btn btn-primary account-btn" name="login" value="DO LOGIN" id="login_button">
                            <!-- <button type="submit" class="btn btn-primary account-btn">Login</button> -->
                        </div>
                        <div class="text-center register-link">
                            Don’t have an account? <a href="register.html">Register Now</a>
                        </div>
                    </form>

The Ajax part would be:

function sendContact() {


    var email = $('#email').val();
    var password = $('#password').val();

    var data = {

        "email": email,
        "password": password,

    };

    jQuery.ajax({
        data: data,
        url: "auth/log.php", // Url to which the request is send
        type: "POST", // Type of request to be send, called as method

        success: function(data)
{
if(data==='success'){

    window.location.replace('index.php');
}
else{
alert('Wrong combination');

}

}

    });
    //  window.location.replace('index.php');


}

The log.php page would be

<?php

include "dbconnection.php";
session_start();

// $email=$_POST['email'];
// $password=$_POST['password'];

$select_data="select * from users where email='". $_POST['email']."' and password='".$_POST['password']."'";
$results= $conn->query($select_data);

if($results->num_rows>0){

$_SESSION["loggedin"] = true;
$_SESSION["user"] = $email;


echo 'success';


}else{
    echo 'fail';

}

?>

Can some here help me.

  • 写回答

0条回答 默认 最新

    报告相同问题?