Hello I just wanna ask about SQL injection currently I am working on a login page but I am getting a little problem about SQL injection I am currently testing a batched SQL code as shown below, I have not yet put an SQL parameter, but it doesn't seem to be working on an SQL injection. My validation is based on row count if it is equal to 0 it will destroy the session and redirected to the index again. The code seems to be working fine, but I am afraid why is it working properly without putting any SQL parameter to prevent SQL injection. I hope someone could explain it, thanks in advance
secured_page.php
<?php
// Start the session
session_start();
// Set session variables
$_SESSION["email"] = $_POST['email'];
$_SESSION["password"] = md5($_POST['password']);
if (isset($_SESSION['email'])){
header('Location: profile.php');
}
else {
header('Location: index.php');
}
?>
profile.php
<?php
// Start the session
session_start();
include('header.php');
include('db_connect.php');
$email = $_SESSION["email"];
$password = $_SESSION["password"];
$sql = "SELECT * FROM user where email = '$email' and password = '$password' LIMIT 1";
$result = $conn->query($sql);
echo $result->num_rows;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["email"]. "<br>";
}
} else {
header('Location: unset_session.php');
}
if (!isset($_SESSION['email'])){
header('Location: index.php');
}
?>
<br>
<a href="unset_session.php">Logout</a>
<?php
$conn->close();
include('footer.php');
?>
$sqland of course knowing what's in the database.