Buenas estoy haciendo un login con usuarios que están en mi base de datos. Estoy intentando poner el de system2 y system3 y no me lo permite. Simplemente me deja el system1, no sé porque.
username es varchar(100) y de cotejamiento es utf8mb4_general_ci y es NULO password es igual que usernameㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ ㅤ LOGIN.PHP
<?php
session_start(); // Starting Session
$error = ''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else{
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("localhost", "root", "", "prueba");
// SQL query to fetch information of registerd users and finds user match.
$query = "SELECT * from systems where username=? AND password=?";
// To protect MySQL injection for Security purpose
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->fetch()) //fetching the contents of the row {
$_SESSION['login_user'] = $username; // Initializing Session
header("location: profile.php"); // Redirecting To Profile Page
}
mysqli_close($conn); // Closing Connection
}
?>
SESSION.PHP
<?php
// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("localhost", "root", "", "prueba");
session_start();// Starting Session
// Storing Session
$user_check = $_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$query = "SELECT * from systems where username = '$user_check'";
$ses_sql = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($ses_sql);
$login_session = $row['username'];
?>
LOGOUT.PHP
<?php
session_start();
if(session_destroy()) // Destroying All Sessions {
header("Location: index.php"); // Redirecting To Home Page
?>
INDEX.PHP
<?php
include('login.php'); // Includes Login Script
if(isset($_SESSION['login_user'])){
header("location: profile.php"); // Redirecting To Profile Page
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hidroponia ABR</title>
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script>
<link href="style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<style>
.parche {
flex-grow: 1;
margin: 100 auto;
position: absolute;,
width: 100%;
}
.message {
background-color: #81BB34;
border-bottom: 10px solid;
}
</style>
<link rel="shortcut icon" type="image/png" href="/minilogo.png"/>
</head>
<body>
<nav></nav>
<center>
<section class="section">
<div class="container">
<div id="login">
<p class="title">
Logeo</p>
<p class="subtitle">Ingresá tu cuenta para acceder al sistema.</p>
<form action="" method="post" class="box" style="width: 700px;">
<div class="field">
<label class="label"><ion-icon name="person-circle-outline"></ion-icon>Nombre del Sistema:</label>
<div class="control">
<input class="input" style="border: 2px solid #81BB34; width: 220px;" id="name" name="username" placeholder="Sistema" type="text">
</div>
</div>
<div class="field">
<label class="label"><ion-icon name="key-outline"></ion-icon>Contraseña</label>
<div class="control">
<input class="input" style="border: 2px solid #81BB34; width: 220px;" id="password" name="password" placeholder="**********" type="password"><br><br>
</div>
</div>
<input name="submit" type="submit" value=" Ingresar " class="button is-primary"style="background-color: #81BB34;"><br><br>
<span><?php echo $error;?></span>
</form>
</div>
</div>
</body>
</html>