One of my friends told me that my validate.php file has some problems with SQL injections. Please feel free to commit it on GitHub.
<?php
session_start();
error_reporting(0);
include("../config.php");
$conn = new mysqli($hostname, $username, $password, $db_name);
$query = mysqli_query($conn,"SELECT * FROM `Administrators` WHERE username = '" . $_POST["usernamep"] . "' AND password='". md5($_POST["passwordp"]) . "'");
if(mysqli_num_rows($query) > 0){
$_SESSION["username"] = $_POST["usernamep"];
header("Location: dashboard.php");
}else{
header("Location: index.php?alert");
}
?>
?>
Can you please try and improve my code to prevent SQL injections?
Bobby'; DROP TABLE Administrators;--
as my user name? (hint: don't try it) \$\endgroup\$ – Phrancis Jan 19 '16 at 16:58mysqli_query
doesn't support multiple queries as far as I know. Still, an attacker can bypass the login check, read out database information, and depending on settings write to files (meaning that they gain code execution). \$\endgroup\$ – tim Jan 19 '16 at 17:03