I am creating a website for a uni assignment.. I have a remember me button and all that good stuff but Someone looked over my code and said that SQL
injection could take place..
what would be the best course of action?
I just need guidance:
<?php
include 'functions.php';
if (loggedin())
{
header("Location: index.php");
exit();
}
if (isset($_POST['login']))
{
$username = $_POST['username'];
$password = $_POST['password'];
if (isset($_POST['rememberme']))
{
$rememberme = $_POST['rememberme'];
}
if ($username && $password)
{
$login = mysql_query("SELECT * FROM users WHERE username='$username'");
while($row = mysql_fetch_assoc($login))
{
$db_password = $row['password'];
if($password == $db_password)
{
$loginok = TRUE;
}
else
{
$loginok = FALSE;
}
if ($loginok == TRUE)
{
if($rememberme == "on")
{
setcookie("username", $username, time() + 7200);
}
else
{
if ($rememberme == "")
{
$_SESSION['username'] = $username;
}
}
header("Location: index.php");
exit();
}