Estoy intentando hacer el siguiente login
Clase Login
Código:
<?php
class Login {
private $conn;
private $table;
public function __construct(){
$db = new Conexion();
$this->conn = $db->getConnection();
$this->table = "usuarios";
}
public function log_into($usuarios, $password){
$res = $conn->query("SELECT * FROM $this->table WHERE username = " . $username . " AND password = " . $password);
if ($res->num_rows > 0) {
if($row = $res->fetch()) {
$_SESSION['username'] = $row['username'];
}
}
}
}
?>
Código:
<?php
require_once "../conexion.php";
require_once "../controller/login.php";
$objLogin = new Login();
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}
$objLogin->log_into($username, $password);
?>
Ajax
Código:
function logIn(){
var username = $("#username").val();
var password = $("#password").val();
if(username.length == "" || password.length == ""){
$("#message").html("Por favor llena los campos").fadeIn();
$("#message").addClass("error");
return false;
}
else{
var dataString = 'username='+username+'&password='+password;
$.ajax({
type : 'POST',
url : 'rest/login.php',
data : dataString,
success : function(data){
console.log(data);
}
});
}
}
Formulario
Código:
<div class="modal-header">
<div id="message"></div>
<form role="form" id="login-form" method="POST">
<div class="form-group">
<input type="text" class="form-control" id="username" name="username" placeholder="Usuario"/><br>
<input type="password" class="form-control" id="password" name="password" placeholder="Contraseña" />
</div>
</form>
</div>
<!-- footer -->
<div class="modal-footer">
<button name="login" id="login" class="btn btn-primary btn-block">Log In</button>
<div id="result"></div>
</div>