I am trying to create a login form, I created the html form and wrote this PHP code but I keep on getting an error about session_start(); and header already sent
The error:
Warning: session_start(): Cannot send session cookie - headers already sent by
<?php
session_start();
if($_POST['submit'])
{
include_once('my_connection.php');
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$sql = "SELECT id,username,password FROM users WHERE username = '$username' AND password = '$password'";
$query = mysqli_query($connect,$sql);
if($query) {
$row = mysqli_fetch_row($query);
$id = $row[0];
$dbusername = $row[1];
$dbpassword = $row[2];
if($username == $dbusername && $password == $dbpassword)
{
$_SESSION['username'] = $username;
$_SESSION['id'] =$id;
header('Location:home.php');
}else {
echo "Incorrect username or password.";
} } }?>
I put the session_start() on the top of the code but still don't work