0
I’m making a login system and when I press the button to log in it displays these two errors here
Warning: mysqli_query(): Couldn’t fetch mysqli in C: xampp htdocs 200cono vlogin.php on line 8
Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, null Given in C: xampp htdocs 200cono vlogin.php on line 9
my login code and this one
<?php
include("admin/bd/config.php");
if (isset($_POST['Usuario']) && isset($_POST['Senha'])) {
$Usuario = $_POST['Usuario'];
$Senha = $_POST['Senha'];
$get = mysqli_query($con,"SELECT * FROM nlogin WHERE Usuario = '$Usuario'");
$num = mysqli_num_rows($get);
if ($num == 1) {
while ($percorrer = mysqli_fetch_assoc($get)) {
if (password_verify ( $_POST['Senha'] , $percorrer['Senha'] )){
$adm = $percorrer['adm'];
$Usuario = $percorrer['Usuario'];
session_start();
if ($adm == 1) {
$_SESSION['adm'] = $Usuario;
header("Location: admin/index.php");
}else{
$_SESSION['nor'] = $username;
header("Location: index.php");
}
}
}
}
}
Code of the Config
<?php
$servername = "localhost";
$database = "site";
$username = "root";
$password = "";
// Create connection
$con = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
mysqli_close($con);
?>
Anyone can help?
It is error in consultation,
mysqli_query($con,"SELECT * FROM nlogin WHERE Usuario = '$Usuario'") or die(mysqli_error($con));
see if there are any errors.– rray
the errors persisted and now appeared this Notice: Use of Undefined Constant con - assumed 'con' in C: xampp htdocs 200cono vlogin.php on line 8
– Wicaro
I think it would be interesting to also put the
config.php
– Lucas Torres
All right, I added
– Wicaro
In your config file you are closing the connection at the end - mysqli_close($con). Remove this line and close the connection at the end of the login file.
– Bins
Thanks, it worked out
– Wicaro
@Bins, don’t you want to add your answer to the question win the 'answered' state? And @ Wicaro accept it as answer?
– Wesley Gonçalves
@Wesleygonçalves, I’ve already added the answer
– Bins