trying to make the user login by getting details but not working please check this
here is my connection code
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "atm";
$conn = new mysqli($server ,$username ,$password ,"atm");
if(!$conn =""){
echo "connection is established<br>";
}
?>
my main file code is
<?php
require_once "../configmain.php";
if(isset($_POST['login'])){
$username = $_POST["username"];
$password = $_POST["password"];
$adminqry = mysqli_query($conn,"select 'admin_id' from 'admin_details' where STATUS = '1' and username = '$username' and password = '$password';")or die (mysqli_error($con));
while($admin = mysqli_fetch_object($adminqry)){
$adminid = $admin -> admin_id;
}
session_start();
$_SESSION['adminid'] = $adminid;
$adminid = $_SESSION['adminid'];
echo $adminid;
if(!$adminid){
header("Location: ./admin/adminmain.php");
exit();
}
else{
echo "login error";
}
}
?>
checked if my connection is working or not it is working if my database is working or not but it is also working iam working with xampp server please help me
2
Answers
Your problem is this line:
You aren’t checking to see if the
$connection
is empty, you’re actually setting it to an empty string.Try changing your check to this:
This will check for any non-zero error numbers on your connection object. You can also get the connection error message with
$conn->connect_error
Try this
STEP 1 : Replace your connection file by below given code
STEP 2 : Replace your main file code by below give code