Cyril Cyril - 10 days ago 4
PHP Question

I can't Login with status activated admin

I want to login with my activated admin or if the admin is not activated/deactivated, it will not login.

I hope you can help me

So here's the code:

if(isset($_POST['Login'])) {
$errors = '';
global $con;

$username = mysql_preparation($_POST['txtusername']);
$password = mysql_preparation($_POST['txtpassword']);
$ss = "SELECT * FROM admin WHERE username = '$username' AND password = '$password'";
$rr = mysqli_query($con, $ss);
$hey = mysqli_fetch_assoc($rr);

$statusQuery = "SELECT * FROM admin WHERE status = '1'";
$statusResult = mysqli_query($con, $statusQuery);
$adminStatus = mysqli_fetch_assoc($statusResult);

if(mysqli_num_rows($rr) > 0) {
$row = mysqli_fetch_assoc($rr);
$_SESSION['id'] = $row['id'];
$type = $row['username'];
$status = $row['status'];
}
elseif($status == 1) {

mysqli_query($con, "INSERT INTO history (date,action,user) VALUES (NOW(), 'Login', '$type')")or die(mysql_error());

header('Location: index.php');
} else {
?>
<script type="text/javascript">
alert('Invalid Login Details');
</script>
<?php
}
}

Answer
SELECT * FROM admin WHERE username = '$username' AND password = '$password' AND  status = '1'

try that as your query it wont get an output if the admin is inactive dont write php for stuff you can deal with sql

and #hashthepass plz :P

Comments