I recently moved to a Linux environment, more specifically "Kali", I installed Xampp and Sublime Text, but when I run my application it doesn't show me anything and it's because the PHP code is written before the HTML. But this did not happen on Windows. Does anyone know what happens?
Structure of my code:
Code that doesn't show me anything:
PHP:
<php
include 'config.php';
session_start();
error_reporting(0);
if (isset($_POST['submit'])) {
$user = $_POST['user'];
$password = md5($_POST['password']);
$sql = "SELECT * FROM users WHERE user='$user' AND password='$password'";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
$row = mysqli_fetch_assoc($result);
$_SESSION['user'] = $row['user'];
header("Location: inicio.php");
} else {
echo "<script>alert('Credenciales incorrectas...')</script>";
}
}
?>
HTML:
<body>
<form>
<p class="login-text" style="font-size: 2rem; font-weight: 800;">Iniciar seión</p>
<div class="input-group">
<input type="text" placeholder="Usuario" name="user" value="<?php echo $user; ?>" required>
</div>
<div class="input-group">
<input type="password" placeholder="Contraseña" name="password" required>
</div>
<div class="input-group">
<button name="submit" class="btn">Iniciar Sesión</button>
</div>
<p class="login-register-text">No tienes una cuenta? <a href="registro.php">Registrate acá</a></p>
</form>
</body>
I code that if it shows me something but the PHP no longer works:
HTML:
<body>
<form>
<p class="login-text" style="font-size: 2rem; font-weight: 800;">Iniciar seión</p>
<div class="input-group">
<input type="text" placeholder="Usuario" name="user" value="<?php echo $user; ?>" required>
</div>
<div class="input-group">
<input type="password" placeholder="Contraseña" name="password" required>
</div>
<div class="input-group">
<button name="submit" class="btn">Iniciar Sesión</button>
</div>
<p class="login-register-text">No tienes una cuenta? <a href="registro.php">Registrate acá</a></p>
</form>
</body>
PHP:
<php
include 'config.php';
session_start();
error_reporting(0);
if (isset($_POST['submit'])) {
$user = $_POST['user'];
$password = md5($_POST['password']);
$sql = "SELECT * FROM users WHERE user='$user' AND password='$password'";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
$row = mysqli_fetch_assoc($result);
$_SESSION['user'] = $row['user'];
header("Location: inicio.php");
} else {
echo "<script>alert('Credenciales incorrectas...')</script>";
}
}
?>
In advance thanks for the help.
There are several things in your code:
<?php
body
HTML tag.Fixing those two things, the code should work (I'll leave error reporting on temporarily to show you errors if there are any, then you can turn it off):